Skip to content

Commit

Permalink
Fix panic with misnamed index section
Browse files Browse the repository at this point in the history
Closes #1244
  • Loading branch information
Keats committed Dec 14, 2020
1 parent 26b8ec6 commit 68cdfcb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 68cdfcb

Please sign in to comment.