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