Compare commits

..

No commits in common. "1310f4fc294923d2b732e9ff93f125f226fd7c02" and "0c4ac137bcf29f2fc19f4a86ecf7f428b3bbc485" have entirely different histories.

5 changed files with 14 additions and 21 deletions

View File

@ -1,7 +1,8 @@
use std::path::Path; use std::path::Path;
use askama_axum::Template;
use axum::http::{StatusCode, Uri}; use axum::http::{StatusCode, Uri};
use axum_htmx::AutoVaryLayer; use axum_htmx::{AutoVaryLayer, HxRequest};
use tower_http::services::ServeDir; use tower_http::services::ServeDir;
mod menu; mod menu;
@ -11,11 +12,21 @@ async fn fallback(uri: Uri) -> (StatusCode, String) {
(StatusCode::NOT_FOUND, format!("No route for {uri}")) (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 { pub fn get_router(assets_path: &Path) -> axum::Router {
axum::Router::new() axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path)) .nest_service("/assets", ServeDir::new(assets_path))
.route("/", axum::routing::get(root))
.merge(pages::get_routes()) .merge(pages::get_routes())
.fallback(fallback) .fallback(fallback)
// The AutoVaryLayer is used to avoid cache issues with htmx (cf: https://github.com/robertwayne/axum-htmx?tab=readme-ov-file#auto-caching-management)
.layer(AutoVaryLayer) .layer(AutoVaryLayer)
} }

View File

@ -4,9 +4,6 @@ pub struct MenuItem {
pub href: String, pub href: String,
} }
/// Get the menu items
/// This function is the central place to define the menu items
/// It can be used directly in templates, for example in the `navbar` component to render the menu
pub fn get_menu_items() -> Vec<MenuItem> { pub fn get_menu_items() -> Vec<MenuItem> {
vec![ vec![
MenuItem { MenuItem {

View File

@ -1,12 +0,0 @@
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 }
}

View File

@ -1,10 +1,7 @@
use axum::{routing, Router}; use axum::{routing, Router};
mod cps; mod cps;
mod home;
pub fn get_routes() -> Router { pub fn get_routes() -> Router {
Router::new() Router::new().route("/cps", routing::get(cps::cps))
.route("/", axum::routing::get(home::home))
.route("/cps", routing::get(cps::cps))
} }