about: add about page and I did smth else but I can't remember
This commit is contained in:
parent
36f670e03a
commit
12bb8d69c1
7 changed files with 54 additions and 22 deletions
|
|
@ -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
33
src/templates/about.rs
Normal 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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod about;
|
||||
pub mod home;
|
||||
pub mod music;
|
||||
pub mod notfound;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue