diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c48462..db1bdde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Fix shortcodes without arguments being ignored - Fix shortcodes with markdown chars (_, *, etc) in name and args being ignored +- Fix subsections of index not being filled without a `_index.md` +- Fix permalink generation for index page ## 0.2.1 (2017-10-17) diff --git a/components/config/src/lib.rs b/components/config/src/lib.rs index 1e709b6..262848b 100644 --- a/components/config/src/lib.rs +++ b/components/config/src/lib.rs @@ -108,7 +108,7 @@ impl Config { /// Makes a url, taking into account that the base url might have a trailing slash pub fn make_permalink(&self, path: &str) -> String { - let trailing_bit = if path.ends_with('/') { "" } else { "/" }; + let trailing_bit = if path.ends_with('/') || path.is_empty() { "" } else { "/" }; // Index section with a base url that has a trailing slash if self.base_url.ends_with('/') && path == "/" { @@ -243,6 +243,21 @@ hello = "world" assert_eq!(config.unwrap().extra.unwrap().get("hello").unwrap().as_str().unwrap(), "world"); } + #[test] + fn can_make_url_index_page_with_non_trailing_slash_url() { + let mut config = Config::default(); + config.base_url = "http://vincent.is".to_string(); + assert_eq!(config.make_permalink(""), "http://vincent.is/"); + } + + + #[test] + fn can_make_url_index_page_with_railing_slash_url() { + let mut config = Config::default(); + config.base_url = "http://vincent.is/".to_string(); + assert_eq!(config.make_permalink(""), "http://vincent.is/"); + } + #[test] fn can_make_url_with_non_trailing_slash_base_url() { let mut config = Config::default(); diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index b018dc5..9f436e0 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -207,7 +207,7 @@ impl Site { if !self.sections.contains_key(&index_path) { let mut index_section = Section::default(); index_section.permalink = self.config.make_permalink(""); - // TODO: need to insert into permalinks too + index_section.file.parent = self.base_path.join("content"); self.sections.insert(index_path, index_section); } @@ -736,8 +736,12 @@ impl Site { Ok(()) } + /// Used only on reload pub fn render_index(&self) -> Result<()> { - self.render_section(&self.sections[&self.base_path.join("content").join("_index.md")], false) + self.render_section( + &self.sections[&self.base_path.join("content").join("_index.md")], + false + ) } /// Renders all sections diff --git a/components/site/test_site/content/_index.md b/components/site/test_site/content/_index.md deleted file mode 100644 index e2be969..0000000 --- a/components/site/test_site/content/_index.md +++ /dev/null @@ -1,3 +0,0 @@ -+++ -title = "Index" -+++