agahnim.dev/src/templates/notfound.rs
2026-03-23 15:27:52 +01:00

34 lines
767 B
Rust

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