Ensure we don't delete root index without

adding back default in rebuild

Fix #620
This commit is contained in:
Vincent Prouillet 2019-02-22 21:48:30 +01:00
parent 11c58458e8
commit 974492bb7b
4 changed files with 46 additions and 18 deletions

View file

@ -116,6 +116,9 @@ fn delete_element(site: &mut Site, path: &Path, is_section: bool) -> Result<()>
}
}
// We might have delete the root _index.md so ensure we have at least the default one
// before populating
site.create_default_index_sections()?;
site.populate_sections();
site.populate_taxonomies()?;
// Ensure we have our fn updated so it doesn't contain the permalink(s)/section/page deleted

View file

@ -269,3 +269,20 @@ Edite
assert!(res.is_ok());
assert!(file_contains!(site_path, "public/fr/blog/with-assets/index.html", "Edite"));
}
// https://github.com/getzola/zola/issues/620
#[test]
fn can_rebuild_after_renaming_section_and_deleting_file() {
let tmp_dir = tempdir().expect("create temp dir");
let (site_path, mut site) = load_and_build_site!(tmp_dir, "test_site");
let (old_path, new_path) = rename!(site_path, "content/posts/", "post/");
let res = after_content_rename(&mut site, &old_path, &new_path);
assert!(res.is_ok());
let path = site_path.join("content").join("_index.md");
fs::remove_file(&path).unwrap();
let res = after_content_change(&mut site, &path);
println!("{:?}", res);
assert!(res.is_ok());
}

View file

@ -234,8 +234,30 @@ impl Site {
self.add_section(s, false)?;
}
// Insert a default index section for each language if necessary so we don't need to create
// a _index.md to render the index page at the root of the site
self.create_default_index_sections()?;
let mut pages_insert_anchors = HashMap::new();
for page in pages {
let p = page?;
pages_insert_anchors.insert(
p.file.path.clone(),
self.find_parent_section_insert_anchor(&p.file.parent.clone(), &p.lang),
);
self.add_page(p, false)?;
}
self.register_early_global_fns();
self.populate_sections();
self.render_markdown()?;
self.populate_taxonomies()?;
self.register_tera_global_fns();
Ok(())
}
/// Insert a default index section for each language if necessary so we don't need to create
/// a _index.md to render the index page at the root of the site
pub fn create_default_index_sections(&mut self) -> Result<()> {
for (index_path, lang) in self.index_section_paths() {
if let Some(ref index_section) = self.library.read().unwrap().get_section(&index_path) {
if self.config.build_search_index && !index_section.meta.in_search_index {
@ -270,22 +292,6 @@ impl Site {
}
}
let mut pages_insert_anchors = HashMap::new();
for page in pages {
let p = page?;
pages_insert_anchors.insert(
p.file.path.clone(),
self.find_parent_section_insert_anchor(&p.file.parent.clone(), &p.lang),
);
self.add_page(p, false)?;
}
self.register_early_global_fns();
self.populate_sections();
self.render_markdown()?;
self.populate_taxonomies()?;
self.register_tera_global_fns();
Ok(())
}

View file

@ -0,0 +1,2 @@
+++
+++