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;
|
// use tower::ServiceBuilder;
|
||||||
|
|
||||||
// mod internal_server_error;
|
// mod internal_server_error;
|
||||||
mod not_found;
|
pub mod not_found;
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
Router::new().fallback(not_found::handler)
|
Router::new().fallback(not_found::handler)
|
||||||
|
|
|
@ -7,10 +7,7 @@ use std::{
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::Path,
|
extract::Path,
|
||||||
http::{
|
http::Response,
|
||||||
Response,
|
|
||||||
StatusCode,
|
|
||||||
},
|
|
||||||
response::{
|
response::{
|
||||||
Html,
|
Html,
|
||||||
IntoResponse,
|
IntoResponse,
|
||||||
|
@ -19,6 +16,7 @@ use axum::{
|
||||||
use maud::Markup;
|
use maud::Markup;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
errors::not_found,
|
||||||
markdown,
|
markdown,
|
||||||
page::{
|
page::{
|
||||||
text,
|
text,
|
||||||
|
@ -27,11 +25,17 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
static PAGES: LazyLock<HashMap<String, Markup>> = LazyLock::new(|| {
|
static PAGES: LazyLock<HashMap<String, Markup>> = LazyLock::new(|| {
|
||||||
|
let routes_path = path::Path::new(file!())
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut pages = HashMap::new();
|
let mut pages = HashMap::new();
|
||||||
|
|
||||||
for file in embed::dir!(".").flatten() {
|
for file in embed::dir!(".").flatten() {
|
||||||
let path = path::Path::new(file.path().as_ref())
|
let path = path::Path::new(file.path().as_ref())
|
||||||
.file_name()
|
.strip_prefix(&routes_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -54,6 +58,6 @@ pub async fn handler(Path(path): Path<String>) -> Response<Body> {
|
||||||
if let Some(body) = PAGES.get(&path) {
|
if let Some(body) = PAGES.get(&path) {
|
||||||
Html(text::create(Some("test"), Page::from_str(&path), &body).into_string()).into_response()
|
Html(text::create(Some("test"), Page::from_str(&path), &body).into_string()).into_response()
|
||||||
} else {
|
} else {
|
||||||
StatusCode::NOT_FOUND.into_response()
|
not_found::handler().await.into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,11 +5,11 @@ use axum::{
|
||||||
|
|
||||||
mod assets;
|
mod assets;
|
||||||
mod index;
|
mod index;
|
||||||
mod mdpage;
|
mod markdown;
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(index::handler))
|
.route("/", get(index::handler))
|
||||||
.route("/:page", get(mdpage::handler))
|
.route("/*page", get(markdown::handler))
|
||||||
.route("/assets/*path", get(assets::handler))
|
.route("/assets/*path", get(assets::handler))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue