Merge pull request #62 from Keats/smarter
Slighty smarter rebuild on page content change
This commit is contained in:
commit
18ccb4b79e
61
src/site.rs
61
src/site.rs
|
@ -212,11 +212,15 @@ impl Site {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called in serve, add a page again updating permalinks and its content
|
/// Called in serve, add a page again updating permalinks and its content
|
||||||
fn add_page_and_render(&mut self, path: &Path) -> Result<()> {
|
/// The bool in the result is whether the front matter has been updated or not
|
||||||
|
fn add_page_and_render(&mut self, path: &Path) -> Result<(bool, Page)> {
|
||||||
|
let existing_page = self.pages.get(path).expect("Page was supposed to exist in add_page_and_render").clone();
|
||||||
self.add_page(path)?;
|
self.add_page(path)?;
|
||||||
let mut page = self.pages.get_mut(path).unwrap();
|
let mut page = self.pages.get_mut(path).unwrap();
|
||||||
self.permalinks.insert(page.relative_path.clone(), page.permalink.clone());
|
self.permalinks.insert(page.relative_path.clone(), page.permalink.clone());
|
||||||
page.render_markdown(&self.permalinks, &self.tera, &self.config)
|
page.render_markdown(&self.permalinks, &self.tera, &self.config)?;
|
||||||
|
|
||||||
|
Ok((existing_page.meta != page.meta, page.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find out the direct subsections of each subsection if there are some
|
/// Find out the direct subsections of each subsection if there are some
|
||||||
|
@ -337,25 +341,37 @@ impl Site {
|
||||||
self.add_section(path)?;
|
self.add_section(path)?;
|
||||||
} else {
|
} else {
|
||||||
// probably just an update so just re-parse that page
|
// probably just an update so just re-parse that page
|
||||||
// TODO: we can compare the frontmatter of the existing and new one
|
let (frontmatter_changed, page) = self.add_page_and_render(path)?;
|
||||||
// to see if we need to update re-build the whole thing or just that
|
// TODO: can probably be smarter and check what changed
|
||||||
// page
|
if frontmatter_changed {
|
||||||
self.add_page_and_render(path)?;
|
self.populate_sections();
|
||||||
}
|
self.populate_tags_and_categories();
|
||||||
} else if is_section {
|
self.build()?;
|
||||||
// File doesn't exist -> a deletion so we remove it from everything
|
|
||||||
let relative_path = self.sections[path].relative_path.clone();
|
|
||||||
self.sections.remove(path);
|
|
||||||
self.permalinks.remove(&relative_path);
|
|
||||||
} else {
|
} else {
|
||||||
let relative_path = self.pages[path].relative_path.clone();
|
self.render_page(&page)?;
|
||||||
self.pages.remove(path);
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// File doesn't exist -> a deletion so we remove it from everything
|
||||||
|
let relative_path = if is_section {
|
||||||
|
self.sections[path].relative_path.clone()
|
||||||
|
} else {
|
||||||
|
self.pages[path].relative_path.clone()
|
||||||
|
};
|
||||||
self.permalinks.remove(&relative_path);
|
self.permalinks.remove(&relative_path);
|
||||||
|
|
||||||
|
if is_section {
|
||||||
|
self.sections.remove(path);
|
||||||
|
} else {
|
||||||
|
self.pages.remove(path);
|
||||||
}
|
}
|
||||||
// TODO: probably no need to do that, we should be able to only re-render a page or a section.
|
// TODO: probably no need to do that, we should be able to only re-render a page or a section.
|
||||||
self.populate_sections();
|
self.populate_sections();
|
||||||
self.populate_tags_and_categories();
|
self.populate_tags_and_categories();
|
||||||
self.build()
|
self.build()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rebuild_after_template_change(&mut self, path: &Path) -> Result<()> {
|
pub fn rebuild_after_template_change(&mut self, path: &Path) -> Result<()> {
|
||||||
|
@ -577,9 +593,6 @@ impl Site {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for section in self.sections.values() {
|
for section in self.sections.values() {
|
||||||
if !section.meta.should_render() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let mut output_path = public.to_path_buf();
|
let mut output_path = public.to_path_buf();
|
||||||
for component in §ion.components {
|
for component in §ion.components {
|
||||||
output_path.push(component);
|
output_path.push(component);
|
||||||
|
@ -589,6 +602,14 @@ impl Site {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for page in §ion.pages {
|
||||||
|
self.render_page(page)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !section.meta.should_render() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if section.meta.is_paginated() {
|
if section.meta.is_paginated() {
|
||||||
self.render_paginated(&output_path, section)?;
|
self.render_paginated(&output_path, section)?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -599,10 +620,6 @@ impl Site {
|
||||||
)?;
|
)?;
|
||||||
create_file(output_path.join("index.html"), &self.inject_livereload(output))?;
|
create_file(output_path.join("index.html"), &self.inject_livereload(output))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for page in §ion.pages {
|
|
||||||
self.render_page(page)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue