This commit is contained in:
2025-09-06 21:49:55 -05:00
parent 271c5f8f28
commit ced39aa878
3 changed files with 7 additions and 23 deletions
+3 -21
View File
@@ -273,35 +273,17 @@ mod tests {
fn find_rendered_index(actions: &Vec<RenderOutput>, path: &str) -> Option<usize> {
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<RenderOutput>, path: &str) -> Option<usize> {
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<RenderOutput>, path: &str) -> Option<usize> {
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]
-1
View File
@@ -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)]
+4 -1
View File
@@ -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()