diff --git a/src/fleen_app.rs b/src/fleen_app.rs index c210f2e..bd467ea 100644 --- a/src/fleen_app.rs +++ b/src/fleen_app.rs @@ -273,35 +273,17 @@ mod tests { fn find_rendered_index(actions: &Vec, path: &str) -> Option { let path = PathBuf::from(path); - actions.iter().position(|a| { - if let RenderOutput::Rendered(p, _) = a && p == &path { - true - } else { - false - } - }) + actions.iter().position(|a| matches!(a, RenderOutput::Rendered(p, _) if p == &path)) } fn find_dir_index(actions: &Vec, path: &str) -> Option { let path = PathBuf::from(path); - actions.iter().position(|a| { - if let RenderOutput::Dir(p) = a && p == &path { - true - } else { - false - } - }) + actions.iter().position(|a| matches!(a, RenderOutput::Dir(p) if p == &path)) } fn find_raw_index(actions: &Vec, path: &str) -> Option { let path = PathBuf::from(path); - actions.iter().position(|a| { - if let RenderOutput::RawFile(p) = a && p == &path { - true - } else { - false - } - }) + actions.iter().position(|a| matches!(a, RenderOutput::RawFile(p) if p == &path)) } #[test] diff --git a/src/renderer.rs b/src/renderer.rs index 23984d4..6c33b5b 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -6,7 +6,6 @@ use markdown::{Constructs, Options, ParseOptions}; use markdown::mdast::Node; use serde::Deserialize; use thiserror::Error; -use crate::fleen_app::FleenError; /// The things we might return from trying to render a file #[derive(Clone, PartialEq, Debug)] diff --git a/src/server.rs b/src/server.rs index 9f91e87..c9e579e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -30,23 +30,26 @@ fn serve_path(path: String, root: PathBuf) -> impl IntoResponse { match render { Ok(RenderOutput::Rendered(_, content)) | Ok(RenderOutput::Hidden(_, content)) => { + // We rendered some output so spit it back Response::builder() .status(200) .body(Body::from(content)).unwrap() } Ok(RenderOutput::RawFile(file)) => { + // We were pointed at the raw contents of a file: Response::builder() .status(200) .body(Body::from(fs::read(root.join(file)).unwrap_or(vec![]))).unwrap() } Ok(RenderOutput::NoOutput) | Ok(RenderOutput::Dir(_)) => { - // TODO a nicer 404 page? + // Asked for something that doesn't exist: Response::builder() .status(404) .body(Body::from(include_str!("../templates/404.html"))).unwrap() } Err(err) => { + // Oh no! Response::builder() .status(500) .body(Body::from(format!("{}", err))).unwrap()