Skip to content

Commit

Permalink
feat: make trimming /index.html from URLs optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcur committed May 3, 2024
1 parent 8990dee commit 1d1ed53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
pub struct SiteConfig {
pub base_url: String,
pub base_url_develop: String,
pub trim_index_html: Option<bool>,
}
4 changes: 3 additions & 1 deletion src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{cli::BuildKind, config::SiteConfig, utils};
struct InnerCtx {
build_kind: BuildKind,
base_url: String,
trim_index_html: bool,
}

/// Site build context. The context is cheap to clone.
Expand All @@ -24,6 +25,7 @@ impl Ctx {
inner: Arc::new(InnerCtx {
build_kind,
base_url: base_url.clone(),
trim_index_html: site_config.trim_index_html.unwrap_or(true),
}),
}
}
Expand All @@ -39,7 +41,7 @@ impl Ctx {
/// Turn a path relative to the output directory into an absolute URL.
pub fn path_to_absolute_url(&self, path: impl AsRef<Path>) -> anyhow::Result<String> {
let mut url = utils::path_to_url(Some(self.base_url()), path)?;
if url.ends_with("/index.html") {
if self.inner.trim_index_html && url.ends_with("/index.html") {
url.truncate(url.len() - "/index.html".len());
}
Ok(url)
Expand Down

0 comments on commit 1d1ed53

Please sign in to comment.