Fix rebuild content logic to include sections

This commit is contained in:
Vincent Prouillet 2017-05-01 16:31:23 +09:00
parent db84411788
commit 566f4e6919

View file

@ -284,25 +284,41 @@ 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.index = Some(Section::from_file(path, &self.config)?);
} else {
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
self.add_page_and_render(path)?; self.add_page_and_render(path)?;
} }
} else { } else {
// new file? // File doesn't exist -> a deletion so we remove it from everything
self.add_page_and_render(path)?; if is_section {
if !is_index_section {
let relative_path = self.sections[path].relative_path.clone();
self.sections.remove(path);
self.permalinks.remove(&relative_path);
} else {
self.index = None;
} }
} else { } else {
// File doesn't exist -> a deletion so we remove it from everything
let relative_path = self.pages[path].relative_path.clone(); let relative_path = self.pages[path].relative_path.clone();
self.pages.remove(path); self.pages.remove(path);
self.permalinks.remove(&relative_path); self.permalinks.remove(&relative_path);
} }
}
self.populate_sections(); self.populate_sections();
self.populate_tags_and_categories(); self.populate_tags_and_categories();
self.build() self.build()