Skip to content

Commit

Permalink
Merge pull request #43 from technosophos/fix/ignore-broken-content
Browse files Browse the repository at this point in the history
if TOML header fails to parse, don't 500 the entire site
  • Loading branch information
technosophos authored Feb 25, 2022
2 parents 8350426 + 82a4a12 commit e5532a8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ pub fn all_pages(dir: PathBuf, show_unpublished: bool) -> anyhow::Result<BTreeMa
continue;
}
let raw_data = std::fs::read_to_string(&f).map_err(|e| anyhow::anyhow!("File is not string data: {:?}: {}", &f, e))?;
let content: Content = raw_data.parse().map_err(|e|anyhow::anyhow!("File {:?}: {}", &f, e))?;
if show_unpublished || content.published {
contents.insert(f.to_string_lossy().to_string(), content.into());
match raw_data.parse::<Content>() {
Ok(content) => {
if show_unpublished || content.published {
contents.insert(f.to_string_lossy().to_string(), content.into());
}
},
Err(e) => {
// If a parse fails, don't take down the entire site. Just skip this piece of content.
eprintln!("File {:?}: {}", &f, e);
continue
}
}
}
Ok(contents)
Expand Down

0 comments on commit e5532a8

Please sign in to comment.