diff --git a/src/errors/mod.rs b/src/errors/mod.rs index 1a779e8..22acd52 100644 --- a/src/errors/mod.rs +++ b/src/errors/mod.rs @@ -5,7 +5,7 @@ use axum::{ // use tower::ServiceBuilder; // mod internal_server_error; -mod not_found; +pub mod not_found; pub fn router() -> Router { Router::new().fallback(not_found::handler) diff --git a/src/routes/mdpage.rs b/src/routes/markdown.rs similarity index 80% rename from src/routes/mdpage.rs rename to src/routes/markdown.rs index c275d6e..3067cbd 100644 --- a/src/routes/mdpage.rs +++ b/src/routes/markdown.rs @@ -7,10 +7,7 @@ use std::{ use axum::{ body::Body, extract::Path, - http::{ - Response, - StatusCode, - }, + http::Response, response::{ Html, IntoResponse, @@ -19,6 +16,7 @@ use axum::{ use maud::Markup; use crate::{ + errors::not_found, markdown, page::{ text, @@ -27,11 +25,17 @@ use crate::{ }; static PAGES: LazyLock> = LazyLock::new(|| { + let routes_path = path::Path::new(file!()) + .parent() + .unwrap() + .canonicalize() + .unwrap(); + let mut pages = HashMap::new(); for file in embed::dir!(".").flatten() { let path = path::Path::new(file.path().as_ref()) - .file_name() + .strip_prefix(&routes_path) .unwrap() .to_str() .unwrap(); @@ -54,6 +58,6 @@ pub async fn handler(Path(path): Path) -> Response { if let Some(body) = PAGES.get(&path) { Html(text::create(Some("test"), Page::from_str(&path), &body).into_string()).into_response() } else { - StatusCode::NOT_FOUND.into_response() + not_found::handler().await.into_response() } } diff --git a/src/routes/mod.rs b/src/routes/mod.rs index d3bc2a2..77c9c99 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -5,11 +5,11 @@ use axum::{ mod assets; mod index; -mod mdpage; +mod markdown; pub fn router() -> Router { Router::new() .route("/", get(index::handler)) - .route("/:page", get(mdpage::handler)) + .route("/*page", get(markdown::handler)) .route("/assets/*path", get(assets::handler)) }