diff --git a/src/blogs.rs b/src/blogs.rs index 6d78946fb..3e4b49f52 100644 --- a/src/blogs.rs +++ b/src/blogs.rs @@ -7,7 +7,7 @@ static POSTS_EXT: &str = "md"; #[derive(Deserialize)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] -pub(crate) struct Manifest { +pub struct Manifest { /// Title to display in the "top row". pub(crate) title: String, @@ -32,7 +32,7 @@ pub(crate) struct Manifest { } #[derive(Serialize)] -pub(crate) struct Blog { +pub struct Blog { title: String, index_title: String, link_text: String, @@ -82,7 +82,7 @@ impl Blog { } } - Ok(Blog { + Ok(Self { title: manifest.title, index_title: manifest.index_title, description: manifest.description, @@ -121,7 +121,7 @@ impl Blog { /// Recursively load blogs in a directory. A blog is a directory with a `blog.yml` /// file inside it. -pub(crate) fn load(base: &Path) -> eyre::Result> { +pub fn load(base: &Path) -> eyre::Result> { let mut blogs = Vec::new(); load_recursive(base, base, &mut blogs)?; Ok(blogs) @@ -140,8 +140,7 @@ fn load_recursive(base: &Path, current: &Path, blogs: &mut Vec) -> eyre::R if file_name == MANIFEST_FILE { let prefix = parent .strip_prefix(base) - .map(|p| p.to_path_buf()) - .unwrap_or_else(|_| PathBuf::new()); + .map_or_else(|_| PathBuf::new(), Path::to_path_buf); blogs.push(Blog::load(prefix, parent)?); } } diff --git a/src/lib.rs b/src/lib.rs index 38e0cfe05..60377bbd4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use self::blogs::Blog; use self::posts::Post; use chrono::Timelike; use eyre::{eyre, WrapErr}; -use handlebars::{handlebars_helper, Handlebars}; +use handlebars::{handlebars_helper, DirectorySourceOptions, Handlebars}; use rayon::prelude::*; use sass_rs::{compile_file, Options}; use serde_derive::Serialize; @@ -54,7 +54,7 @@ impl<'a> Generator<'a> { ) -> eyre::Result { let mut handlebars = Handlebars::new(); handlebars.set_strict_mode(true); - handlebars.register_templates_directory("templates", Default::default())?; + handlebars.register_templates_directory("templates", DirectorySourceOptions::default())?; handlebars.register_helper("month_name", Box::new(hb_month_name_helper)); Ok(Generator { @@ -96,8 +96,8 @@ impl<'a> Generator<'a> { } fn compile_sass(&self, filename: &str) -> eyre::Result<()> { - let scss_file = format!("./src/styles/{}.scss", filename); - let css_file = format!("./static/styles/{}.css", filename); + let scss_file = format!("./src/styles/{filename}.scss"); + let css_file = format!("./static/styles/{filename}.css"); let css = compile_file(&scss_file, Options::default()) .map_err(|error| eyre!(error)) @@ -113,7 +113,7 @@ impl<'a> Generator<'a> { fn concat_vendor_css(&self, files: Vec<&str>) -> eyre::Result<()> { let mut concatted = String::new(); for filestem in files { - let vendor_path = format!("./static/styles/{}.css", filestem); + let vendor_path = format!("./static/styles/{filestem}.css"); let contents = fs::read_to_string(vendor_path).wrap_err("couldn't read vendor css")?; concatted.push_str(&contents); } diff --git a/src/posts.rs b/src/posts.rs index bbfd6622d..a1672e9db 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -15,7 +15,7 @@ struct YamlHeader { } #[derive(Debug, Clone, Serialize)] -pub(crate) struct Post { +pub struct Post { pub(crate) filename: String, pub(crate) layout: String, pub(crate) title: String, @@ -114,26 +114,21 @@ impl Post { } // If they supplied team, it should look like `team-text ` - let (team, team_url) = match team_string { - Some(s) => { - lazy_static::lazy_static! { - static ref R: Regex = Regex::new(r"(?P[^<]*) <(?P[^>]+)>").unwrap(); - } - let captures = match R.captures(&s) { - Some(c) => c, - None => panic!( - "team from path `{}` should have format `$name <$url>`", - path.display() - ), - }; - ( - Some(captures["name"].to_string()), - Some(captures["url"].to_string()), - ) + let (team, team_url) = team_string.map_or((None, None), |s| { + lazy_static::lazy_static! { + static ref R: Regex = Regex::new(r"(?P[^<]*) <(?P[^>]+)>").unwrap(); } - - None => (None, None), - }; + let Some(captures) = R.captures(&s) else { + panic!( + "team from path `{}` should have format `$name <$url>`", + path.display() + ) + }; + ( + Some(captures["name"].to_string()), + Some(captures["url"].to_string()), + ) + }); Ok(Self { filename,