Upstream Pagefind/pagefind state of the touched files before f1eedafd11

This commit is contained in:
upstream committed 2026-10-03 01:43:17 +02:00
1 parent b572112ae7
commit 1308f3c1bb
10 files changed
+1706 -79

No files matched your search

+9 -38
View File
@@ -7,7 +7,6 @@ use hashbrown::HashMap;
use lazy_static::lazy_static;
use pagefind_stem::{Algorithm, Stemmer};
use path_slash::PathExt as _;
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
use regex::Regex;
use std::collections::BTreeMap;
use std::io::BufRead;
@@ -590,20 +589,6 @@ impl Fossicker {
}
/// The URL spec's path percent-encode set, minus `/` so that the separators
/// between the path segments survive. `%` is deliberately left alone, so a file
/// that is already named in encoded form keeps the URL it has today.
const PATH_ENCODE_SET: &AsciiSet = &CONTROLS
.add(b' ')
.add(b'"')
.add(b'#')
.add(b'<')
.add(b'>')
.add(b'?')
.add(b'`')
.add(b'{')
.add(b'}');
fn strip_index_html(url: &str) -> &str {
if url.ends_with("/index.html") {
&url[..url.len() - 10]
@@ -636,7 +621,13 @@ fn build_url(page_url: &Path, relative_to: Option<&Path>, options: &SearchOption
url.to_slash_lossy().to_owned().to_string()
};
format!("/{}", utf8_percent_encode(&final_url, PATH_ENCODE_SET))
format!(
"/{}",
final_url
.replace('%', "%25")
.replace('#', "%23")
.replace('?', "%3F")
)
}
fn normalize_content(content: &str) -> String {
@@ -1260,29 +1251,9 @@ mod tests {
let p: PathBuf = cwd.join::<PathBuf>("hello/world/index.html".into());
let root: PathBuf = cwd.join::<PathBuf>("hello".into());
assert_eq!(&build_url(&p, Some(&root), &opts), "/world/");
}
#[cfg(not(target_os = "windows"))]
#[test]
fn building_urls_with_characters_that_need_encoding() {
std::env::set_var("PAGEFIND_SITE", "hello/world");
let config =
PagefindInboundConfig::with_layers(&[Layer::Env(Some("PAGEFIND_".into()))]).unwrap();
let opts = SearchOptions::load(config).unwrap();
let cwd = std::env::current_dir().unwrap();
let p: PathBuf = cwd.join::<PathBuf>("hello/world/Müsli.html".into());
assert_eq!(&build_url(&p, None, &opts), "/M%C3%BCsli.html");
let p: PathBuf = cwd.join::<PathBuf>("hello/world/Müsli/index.html".into());
assert_eq!(&build_url(&p, None, &opts), "/M%C3%BCsli/");
let p: PathBuf = cwd.join::<PathBuf>("hello/world/a b/c#d?e.html".into());
assert_eq!(&build_url(&p, None, &opts), "/a%20b/c%23d%3Fe.html");
let p: PathBuf = cwd.join::<PathBuf>("hello/world/M%C3%BCsli.html".into());
assert_eq!(&build_url(&p, None, &opts), "/M%C3%BCsli.html");
let p: PathBuf = cwd.join::<PathBuf>("hello/world/100%/C#/why?.html".into());
assert_eq!(&build_url(&p, None, &opts), "/100%25/C%23/why%3F.html");
}
#[cfg(target_os = "windows")]
+1 -17
View File
@@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use clap::Parser;
use rust_patch::Patch;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, env, path::PathBuf};
use std::{env, path::PathBuf};
use twelf::config;
use typed_builder::TypedBuilder;
@@ -22,15 +22,6 @@ use crate::{
// No options should be added that are required.
//
/// A selector paired with the Pagefind attributes to set on the elements it matches,
/// so a site can be configured with the same vocabulary its HTML would use.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
pub(crate) struct PagefindRule {
pub(crate) selector: String,
#[serde(default)]
pub(crate) attributes: BTreeMap<String, String>,
}
#[config]
#[derive(Parser, Debug, Clone)]
#[clap(author, version, about, long_about = None)]
@@ -83,11 +74,6 @@ pub(crate) struct PagefindInboundConfig {
#[serde(default)]
pub(crate) exclude_selectors: Vec<String>,
/// Not a CLI flag: a list of selectors with attribute maps does not fit an argument.
#[clap(skip)]
#[serde(default)]
pub(crate) rules: Vec<PagefindRule>,
#[clap(
long,
help = "The file glob Pagefind uses to find HTML files. Defaults to \"**/*.{html}\""
@@ -241,7 +227,6 @@ pub(crate) struct SearchOptions {
pub(crate) bundle_output: PathBuf,
pub(crate) root_selector: String,
pub(crate) exclude_selectors: Vec<String>,
pub(crate) rules: Vec<PagefindRule>,
pub(crate) glob: String,
pub(crate) force_language: Option<String>,
pub(crate) include_characters: Vec<char>,
@@ -323,7 +308,6 @@ impl SearchOptions {
bundle_output,
root_selector: config.root_selector,
exclude_selectors: config.exclude_selectors,
rules: config.rules,
glob: config.glob,
force_language: config.force_language,
include_characters,