From 404240ef829d707edfc58f8360a5eb113a8b4984 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 24 Oct 2017 20:11:39 +0200 Subject: [PATCH] Fix some index related bugs --- CHANGELOG.md | 2 ++ components/config/src/lib.rs | 17 ++++++++++++++++- components/site/src/lib.rs | 8 ++++++-- components/site/test_site/content/_index.md | 3 --- 4 files changed, 24 insertions(+), 6 deletions(-) delete mode 100644 components/site/test_site/content/_index.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c48462c..db1bddee 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 1e709b62..262848be 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 b018dc57..9f436e0b 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 e2be969a..00000000 --- a/components/site/test_site/content/_index.md +++ /dev/null @@ -1,3 +0,0 @@ -+++ -title = "Index" -+++