From 195b760fdc5ccdc68b240a66681446d159e0c2ce Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 12 Sep 2017 16:13:10 +0900 Subject: [PATCH] Fix subsection pages not being filled correctly --- components/site/src/lib.rs | 20 ++++++++++++++----- .../site/test_site/templates/section.html | 1 + components/site/tests/site.rs | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 557e9a1..8733497 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -304,10 +304,14 @@ impl Site { /// Find out the direct subsections of each subsection if there are some /// as well as the pages for each section pub fn populate_sections(&mut self) { - let mut grandparent_paths = HashMap::new(); + let mut grandparent_paths: HashMap> = HashMap::new(); + for section in self.sections.values_mut() { if let Some(ref grand_parent) = section.file.grand_parent { - grandparent_paths.entry(grand_parent.to_path_buf()).or_insert_with(|| vec![]).push(section.clone()); + grandparent_paths + .entry(grand_parent.to_path_buf()) + .or_insert_with(|| vec![]) + .push(section.file.path.clone()); } // Make sure the pages of a section are empty since we can call that many times on `serve` section.pages = vec![]; @@ -321,14 +325,20 @@ impl Site { } } + self.sort_sections_pages(None); + // TODO: remove this clone + let sections = self.sections.clone(); + for section in self.sections.values_mut() { match grandparent_paths.get(§ion.file.parent) { - Some(paths) => section.subsections.extend(paths.clone()), + Some(paths) => { + for p in paths { + section.subsections.push(sections[p].clone()); + } + }, None => continue, }; } - - self.sort_sections_pages(None); } /// Sorts the pages of the section at the given path diff --git a/components/site/test_site/templates/section.html b/components/site/test_site/templates/section.html index cf4b1d1..6a3c8ae 100644 --- a/components/site/test_site/templates/section.html +++ b/components/site/test_site/templates/section.html @@ -6,5 +6,6 @@ {% endfor %} {% for subsection in section.subsections %} {{subsection.title}} + Sub-pages: {{subsection.pages | length}} {% endfor %} {% endblock content %} diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 659304b..cf52c09 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -115,6 +115,8 @@ fn can_build_site_without_live_reload() { assert!(file_exists!(public, "posts/tutorials/index.html")); assert!(file_exists!(public, "posts/tutorials/devops/index.html")); assert!(file_exists!(public, "posts/tutorials/programming/index.html")); + // Ensure subsection pages are correctly filled + assert!(file_contains!(public, "posts/tutorials/index.html", "Sub-pages: 2")); // TODO: add assertion for syntax highlighting // aliases work