mirror of
https://github.com/RGBCube/Site
synced 2025-08-01 13:37:49 +00:00
Fix 404 in markdown paging
This commit is contained in:
parent
7010360f04
commit
23ba898583
3 changed files with 13 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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<HashMap<String, Markup>> = 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<String>) -> Response<Body> {
|
|||
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()
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue