about: add about page and I did smth else but I can't remember

This commit is contained in:
Agahnim 2026-05-13 14:44:57 +02:00
parent 351a133914
commit 6c0a24c883
7 changed files with 54 additions and 22 deletions

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use agahnim_web_v2::{
domain::AppState,
templates::{home::home, music::music, notfound::notfound},
templates::{about::about, home::home, music::music, notfound::notfound},
};
use axum::{Router, routing::get};
use tower_http::services::ServeDir;
@ -16,6 +16,7 @@ async fn main() {
let app = Router::new()
.route("/home", get(home))
.route("/music", get(music))
.route("/about", get(about))
.nest_service("/static", ServeDir::new("static"))
.fallback(notfound)
.with_state(state);

33
src/templates/about.rs Normal file
View file

@ -0,0 +1,33 @@
use askama::Template;
use axum::{
extract::State,
http::HeaderMap,
response::{Html, IntoResponse},
};
use std::sync::Arc;
use crate::domain::AppState;
#[derive(Template)]
#[template(path = "about.html")]
struct AboutTemplate<'a> {
tracks: &'a Vec<crate::domain::Track>,
}
#[derive(Template)]
#[template(path = "partials/about.html")]
struct AboutPartialTemplate {}
pub async fn about(headers: HeaderMap, state: State<Arc<AppState>>) -> impl IntoResponse {
if headers.contains_key("hx-request") {
Html(AboutPartialTemplate {}.render().unwrap())
} else {
Html(
AboutTemplate {
tracks: &state.mp_tracks,
}
.render()
.unwrap(),
)
}
}

View file

@ -1,3 +1,4 @@
pub mod about;
pub mod home;
pub mod music;
pub mod notfound;