Skip to content

Commit

Permalink
Merge pull request #604 from dscho/be-careful-about-stripping-index.h…
Browse files Browse the repository at this point in the history
…tml-from-the-url

Be more careful about special-casing `index.html`
  • Loading branch information
bglw authored May 7, 2024
2 parents f6f67d5 + 3d68de2 commit b09760a
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 b09760a

Please sign in to comment.