From 5082e0f15a9a0cc39061c3ac91c96c634bb0b439 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 30 Jan 2019 09:15:46 +0100 Subject: [PATCH] Render all relevant parent sections on rebuild --- components/library/src/library.rs | 16 ++++++++++------ components/rebuild/src/lib.rs | 9 +++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/library/src/library.rs b/components/library/src/library.rs index ad295e8..793e70f 100644 --- a/components/library/src/library.rs +++ b/components/library/src/library.rs @@ -331,15 +331,19 @@ impl Library { .collect() } - pub fn find_parent_section>(&self, path: P) -> Option<&Section> { - let page_key = self.paths_to_pages[path.as_ref()]; - for s in self.sections.values() { - if s.pages.contains(&page_key) { - return Some(s); + /// Find the parent section & all grandparents section that have transparent=true + /// Only used in rebuild. + pub fn find_parent_sections>(&self, path: P) -> Vec<&Section> { + let mut parents = vec![]; + let page = self.get_page(path.as_ref()).unwrap(); + for ancestor in page.ancestors.iter().rev() { + let section = self.get_section_by_key(*ancestor); + if parents.is_empty() || section.meta.transparent { + parents.push(section); } } - None + parents } /// Only used in tests diff --git a/components/rebuild/src/lib.rs b/components/rebuild/src/lib.rs index 7ef87a1..9ba83cb 100644 --- a/components/rebuild/src/lib.rs +++ b/components/rebuild/src/lib.rs @@ -178,9 +178,9 @@ fn handle_section_editing(site: &mut Site, path: &Path) -> Result<()> { } } -macro_rules! render_parent_section { +macro_rules! render_parent_sections { ($site: expr, $path: expr) => { - if let Some(s) = $site.library.read().unwrap().find_parent_section($path) { + for s in $site.library.read().unwrap().find_parent_sections($path) { $site.render_section(s, false)?; }; }; @@ -204,7 +204,7 @@ fn handle_page_editing(site: &mut Site, path: &Path) -> Result<()> { // Other than the page itself, the summary might be seen // on a paginated list for a blog for example if library.get_page(&pathbuf).unwrap().summary.is_some() { - render_parent_section!(site, path); + render_parent_sections!(site, path); } return site.render_page(&library.get_page(&pathbuf).unwrap()); } @@ -215,6 +215,7 @@ fn handle_page_editing(site: &mut Site, path: &Path) -> Result<()> { &site.library.read().unwrap().get_page(&pathbuf).unwrap().meta, &prev.meta, ); + for change in changes { site.register_tera_global_fns(); @@ -228,7 +229,7 @@ fn handle_page_editing(site: &mut Site, path: &Path) -> Result<()> { site.render_index()?; } PageChangesNeeded::Render => { - render_parent_section!(site, path); + render_parent_sections!(site, path); site.render_page(&site.library.read().unwrap().get_page(&path.to_path_buf()).unwrap())?; } };