diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 97de19f5..e9209b63 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -83,8 +83,9 @@ pub fn execute(args: &ArgMatches) -> Result<()> { .config .get("output.html.input-404") .map(toml::Value::as_str) - .flatten(); - let file_404 = get_404_output_file(input_404); + .flatten() + .map(ToString::to_string); + let file_404 = get_404_output_file(&input_404); // A channel used to broadcast to any websockets to reload when a file changes. let (tx, _rx) = tokio::sync::broadcast::channel::(100); diff --git a/src/config.rs b/src/config.rs index f6825c39..cbcf3e91 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1023,7 +1023,7 @@ mod tests { let html_config = got.html_config().unwrap(); assert_eq!(html_config.input_404, None); assert_eq!( - &get_404_output_file(html_config.input_404.as_deref()), + &get_404_output_file(&html_config.input_404), "404.html" ); } @@ -1040,7 +1040,7 @@ mod tests { let html_config = got.html_config().unwrap(); assert_eq!(html_config.input_404, Some("missing.md".to_string())); assert_eq!( - &get_404_output_file(html_config.input_404.as_deref()), + &get_404_output_file(&html_config.input_404), "missing.html" ); } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index dcc12579..e1ca9a15 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -152,7 +152,7 @@ impl HtmlHandlebars { let rendered = handlebars.render("index", &data_404)?; let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition); - let output_file = get_404_output_file(html_config.input_404.as_deref()); + let output_file = get_404_output_file(&html_config.input_404); utils::fs::write_file(&destination, output_file, rendered.as_bytes())?; debug!("Creating 404.html ✓"); Ok(()) diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 6b7529db..a1bea133 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -177,8 +177,8 @@ pub fn copy_files_except_ext( Ok(()) } -pub fn get_404_output_file(input_404: Option<&str>) -> String { - input_404.unwrap_or("404.md").replace(".md", ".html") +pub fn get_404_output_file(input_404: &Option) -> String { + input_404.as_ref().unwrap_or(&"404.md".to_string()).replace(".md", ".html") } #[cfg(test)]