refacto: move home code into a dedicated file and rename index to home everywhere
This commit is contained in:
parent
ab908f2664
commit
b7fcfe3792
@ -1,8 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use askama_axum::Template;
|
||||
use axum::http::{StatusCode, Uri};
|
||||
use axum_htmx::{AutoVaryLayer, HxRequest};
|
||||
use axum_htmx::AutoVaryLayer;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
mod menu;
|
||||
@ -12,20 +11,9 @@ async fn fallback(uri: Uri) -> (StatusCode, String) {
|
||||
(StatusCode::NOT_FOUND, format!("No route for {uri}"))
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
pub struct GetIndexTemplate {
|
||||
hx_request: bool,
|
||||
}
|
||||
|
||||
async fn root(HxRequest(hx_request): HxRequest) -> GetIndexTemplate {
|
||||
GetIndexTemplate { hx_request }
|
||||
}
|
||||
|
||||
pub fn get_router(assets_path: &Path) -> axum::Router {
|
||||
axum::Router::new()
|
||||
.nest_service("/assets", ServeDir::new(assets_path))
|
||||
.route("/", axum::routing::get(root))
|
||||
.merge(pages::get_routes())
|
||||
.fallback(fallback)
|
||||
.layer(AutoVaryLayer)
|
||||
|
12
crates/app/src/pages/home.rs
Normal file
12
crates/app/src/pages/home.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use askama_axum::Template;
|
||||
use axum_htmx::HxRequest;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "home.html")]
|
||||
pub struct GetHomeTemplate {
|
||||
hx_request: bool,
|
||||
}
|
||||
|
||||
pub async fn home(HxRequest(hx_request): HxRequest) -> GetHomeTemplate {
|
||||
GetHomeTemplate { hx_request }
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
use axum::{routing, Router};
|
||||
|
||||
mod cps;
|
||||
mod home;
|
||||
|
||||
pub fn get_routes() -> Router {
|
||||
Router::new().route("/cps", routing::get(cps::cps))
|
||||
Router::new()
|
||||
.route("/", axum::routing::get(home::home))
|
||||
.route("/cps", routing::get(cps::cps))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user