Render all relevant parent sections on rebuild
This commit is contained in:
parent
1c7729cac6
commit
5082e0f15a
|
@ -331,15 +331,19 @@ impl Library {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn find_parent_section<P: AsRef<Path>>(&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<P: AsRef<Path>>(&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
|
||||
|
|
|
@ -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())?;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue