Browse Source

Ensure we don't delete root index without

adding back default in rebuild

Fix #620
index-subcmd
Vincent Prouillet 5 years ago
parent
commit
974492bb7b
4 changed files with 46 additions and 18 deletions
  1. +3
    -0
      components/rebuild/src/lib.rs
  2. +17
    -0
      components/rebuild/tests/rebuild.rs
  3. +24
    -18
      components/site/src/lib.rs
  4. +2
    -0
      test_site/content/_index.md

+ 3
- 0
components/rebuild/src/lib.rs 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_sections();
site.populate_taxonomies()?; site.populate_taxonomies()?;
// Ensure we have our fn updated so it doesn't contain the permalink(s)/section/page deleted // Ensure we have our fn updated so it doesn't contain the permalink(s)/section/page deleted


+ 17
- 0
components/rebuild/tests/rebuild.rs View File

@@ -269,3 +269,20 @@ Edite
assert!(res.is_ok()); assert!(res.is_ok());
assert!(file_contains!(site_path, "public/fr/blog/with-assets/index.html", "Edite")); 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());
}

+ 24
- 18
components/site/src/lib.rs View File

@@ -234,8 +234,30 @@ impl Site {
self.add_section(s, false)?; 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() { for (index_path, lang) in self.index_section_paths() {
if let Some(ref index_section) = self.library.read().unwrap().get_section(&index_path) { 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 { 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(()) Ok(())
} }




+ 2
- 0
test_site/content/_index.md View File

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

Loading…
Cancel
Save