Fix rebuild content logic to include sections
This commit is contained in:
parent
db84411788
commit
566f4e6919
34
src/site.rs
34
src/site.rs
|
@ -284,24 +284,40 @@ impl Site {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rebuild_after_content_change(&mut self, path: &Path) -> Result<()> {
|
pub fn rebuild_after_content_change(&mut self, path: &Path) -> Result<()> {
|
||||||
|
let is_section = path.ends_with("_index.md");
|
||||||
|
let is_index_section = if is_section {
|
||||||
|
path.parent().unwrap() == self.base_path.join("content")
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
// file exists, either a new one or updating content
|
// file exists, either a new one or updating content
|
||||||
if self.pages.contains_key(path) {
|
if is_section {
|
||||||
if path.ends_with("_index.md") {
|
if is_index_section {
|
||||||
self.add_section(path)?;
|
self.index = Some(Section::from_file(path, &self.config)?);
|
||||||
} else {
|
} else {
|
||||||
// probably just an update so just re-parse that page
|
self.add_section(path)?;
|
||||||
self.add_page_and_render(path)?;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// new file?
|
// probably just an update so just re-parse that page
|
||||||
self.add_page_and_render(path)?;
|
self.add_page_and_render(path)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// File doesn't exist -> a deletion so we remove it from everything
|
// File doesn't exist -> a deletion so we remove it from everything
|
||||||
let relative_path = self.pages[path].relative_path.clone();
|
if is_section {
|
||||||
self.pages.remove(path);
|
if !is_index_section {
|
||||||
self.permalinks.remove(&relative_path);
|
let relative_path = self.sections[path].relative_path.clone();
|
||||||
|
self.sections.remove(path);
|
||||||
|
self.permalinks.remove(&relative_path);
|
||||||
|
} else {
|
||||||
|
self.index = None;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let relative_path = self.pages[path].relative_path.clone();
|
||||||
|
self.pages.remove(path);
|
||||||
|
self.permalinks.remove(&relative_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.populate_sections();
|
self.populate_sections();
|
||||||
self.populate_tags_and_categories();
|
self.populate_tags_and_categories();
|
||||||
|
|
Loading…
Reference in a new issue