use crate::html; use askama::Template; use axum::response::IntoResponse; use axum::{routing::get, Router}; use tower_http::services::ServeDir; pub fn get_router() -> Router { let assets_path = std::env::current_dir().unwrap(); Router::new() .nest("/api", html::api::get_router()) .nest("/blog", html::blog::get_router()) .nest("/projects", html::projects::get_router()) .route("/", get(home)) .route("/now", get(now)) .route("/about", get(about)) .route("/contact", get(contact)) .nest_service( "/assets", ServeDir::new(format!("{}/assets", assets_path.to_str().unwrap())), ) } async fn home() -> impl IntoResponse { let template = HomeTemplate { active_navbar: html::NavBar::HOME, }; html::HtmlTemplate(template) } #[derive(Template)] #[template(path = "home.html")] struct HomeTemplate { active_navbar: &'static str, } pub async fn blog() -> impl IntoResponse { let template = BlogTemplate { active_navbar: html::NavBar::BLOG }; html::HtmlTemplate(template) } #[derive(Template)] #[template(path = "blog.html")] struct BlogTemplate { active_navbar: &'static str, } pub async fn projects() -> impl IntoResponse { let template = ProjectsTemplate { active_navbar: html::NavBar::PROJECTS, }; html::HtmlTemplate(template) } #[derive(Template)] #[template(path = "projects.html")] struct ProjectsTemplate { active_navbar: &'static str, } async fn now() -> impl IntoResponse { let template = NowTemplate { active_navbar: html::NavBar::NOW, }; html::HtmlTemplate(template) } #[derive(Template)] #[template(path = "now.html")] struct NowTemplate { active_navbar: &'static str, } async fn about() -> impl IntoResponse { let template = AboutTemplate { active_navbar: html::NavBar::ABOUT, }; html::HtmlTemplate(template) } #[derive(Template)] #[template(path = "about.html")] struct AboutTemplate { active_navbar: &'static str, } async fn contact() -> impl IntoResponse { let template = ContactTemplate { active_navbar: html::NavBar::CONTACT }; html::HtmlTemplate(template) } #[derive(Template)] #[template(path = "contact.html")] struct ContactTemplate { active_navbar: &'static str, }