feat: implement htmx with partials on index and cps pages

This commit is contained in:
2024-08-23 19:46:28 +02:00
committed by florian_briand
parent 2236a7219b
commit 7d4dc81df2
9 changed files with 63 additions and 43 deletions

View File

@ -2,6 +2,7 @@ use std::path::Path;
use askama_axum::Template;
use axum::http::{StatusCode, Uri};
use axum_htmx::{AutoVaryLayer, HxRequest};
use tower_http::services::ServeDir;
mod menu;
@ -13,10 +14,12 @@ async fn fallback(uri: Uri) -> (StatusCode, String) {
#[derive(Template)]
#[template(path = "index.html")]
pub struct GetIndexTemplate;
pub struct GetIndexTemplate {
hx_request: bool,
}
async fn root() -> GetIndexTemplate {
GetIndexTemplate {}
async fn root(HxRequest(hx_request): HxRequest) -> GetIndexTemplate {
GetIndexTemplate { hx_request }
}
pub fn get_router(assets_path: &Path) -> axum::Router {
@ -25,4 +28,5 @@ pub fn get_router(assets_path: &Path) -> axum::Router {
.route("/", axum::routing::get(root))
.merge(pages::get_routes())
.fallback(fallback)
.layer(AutoVaryLayer)
}