Skip to content

Commit

Permalink
Only strip index.html if it is at the end
Browse files Browse the repository at this point in the history
... and only if it is the full file name...

I noticed this because I want to convert https://git-scm.com/ to use
Pagefind, but any search hitting `/docs/git-checkout-index.html` would
mistakenly link to `/docs/git-checkout-`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 23, 2024
1 parent f6f67d5 commit 3d68de2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pagefind/src/fossick/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ impl Fossicker {
}
}

fn strip_index_html(url: &str) -> &str {
if url.ends_with("/index.html") {
&url[..url.len() - 10]
} else if url == "index.html" {
""
} else {
url
}
}

fn build_url(page_url: &Path, relative_to: Option<&Path>, options: &SearchOptions) -> String {
let prefix = relative_to.unwrap_or(&options.site_source);

Expand All @@ -503,7 +513,7 @@ fn build_url(page_url: &Path, relative_to: Option<&Path>, options: &SearchOption
};

let final_url: String = if !options.keep_index_url {
url.to_slash_lossy().to_owned().replace("index.html", "")
strip_index_html(&url.to_slash_lossy()).to_string()
} else {
url.to_slash_lossy().to_owned().to_string()
};
Expand Down

0 comments on commit 3d68de2

Please sign in to comment.