From 68cdfcbbe7280e9a56a96581b9c29587d58fceb2 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Mon, 14 Dec 2020 22:51:28 +0100 Subject: [PATCH] Fix panic with misnamed index section Closes #1244 --- components/site/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 015ac1c0..400ade3e 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -174,6 +174,9 @@ impl Site { // which we can only decide to use after we've deserialised the section // so it's kinda necessecary let mut dir_walker = WalkDir::new(format!("{}/{}", base_path, "content/")).into_iter(); + let mut allowed_index_filenames: Vec<_> = self.config.languages.iter().map(|l| format!("_index.{}.md", l.code)).collect(); + allowed_index_filenames.push("_index.md".to_string()); + loop { let entry: DirEntry = match dir_walker.next() { None => break, @@ -222,11 +225,14 @@ impl Site { Ok(f) => { let path_str = f.path().file_name().unwrap().to_str().unwrap(); if f.path().is_file() - && path_str.starts_with("_index.") - && path_str.ends_with(".md") + && allowed_index_filenames.iter().find(|&s| *s == path_str).is_some() { Some(f) } else { + // https://github.com/getzola/zola/issues/1244 + if path_str.starts_with("_index.") { + println!("Expected a section filename, got `{}`. Allowed values: `{:?}`", path_str, &allowed_index_filenames); + } None } }