From 40ef634439fbe0bc0b780650166b57aa318016f6 Mon Sep 17 00:00:00 2001 From: James Munns Date: Fri, 20 Apr 2018 02:12:02 +0200 Subject: [PATCH] Allow creation of specific html aliases --- components/site/src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 97968aa2..2af66085 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -600,14 +600,27 @@ impl Site { for page in self.pages.values() { for alias in &page.meta.aliases { let mut output_path = self.output_path.to_path_buf(); - for component in alias.split('/') { + let mut split = alias.split('/').collect::>(); + + // If the alias ends with an html file name, use that instead of mapping + // as a path containing an `index.html` + let page_name: String = match split.pop() { + Some(part) if part.ends_with(".html") => part.to_string(), + Some(part) => { + split.push(part); + "index.html".into() + } + None => "index.html".into() + }; + + for component in split { output_path.push(&component); if !output_path.exists() { create_directory(&output_path)?; } } - create_file(&output_path.join("index.html"), &render_redirect_template(&page.permalink, &self.tera)?)?; + create_file(&output_path.join(&page_name), &render_redirect_template(&page.permalink, &self.tera)?)?; } } Ok(())