2024-03-24 10:45:16 -04:00
|
|
|
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 {
|
2024-03-24 15:12:36 -04:00
|
|
|
let template = HomeTemplate {
|
|
|
|
|
active_navbar: html::NavBar::HOME,
|
|
|
|
|
};
|
2024-03-24 10:45:16 -04:00
|
|
|
html::HtmlTemplate(template)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "home.html")]
|
2024-03-24 15:12:36 -04:00
|
|
|
struct HomeTemplate {
|
|
|
|
|
active_navbar: &'static str,
|
|
|
|
|
}
|
2024-03-24 10:45:16 -04:00
|
|
|
|
|
|
|
|
pub async fn blog() -> impl IntoResponse {
|
2024-03-24 15:12:36 -04:00
|
|
|
let template = BlogTemplate {
|
|
|
|
|
active_navbar: html::NavBar::BLOG
|
|
|
|
|
};
|
2024-03-24 10:45:16 -04:00
|
|
|
html::HtmlTemplate(template)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "blog.html")]
|
2024-03-24 15:12:36 -04:00
|
|
|
struct BlogTemplate {
|
|
|
|
|
active_navbar: &'static str,
|
|
|
|
|
}
|
2024-03-24 10:45:16 -04:00
|
|
|
|
|
|
|
|
pub async fn projects() -> impl IntoResponse {
|
2024-03-24 15:12:36 -04:00
|
|
|
let template = ProjectsTemplate {
|
|
|
|
|
active_navbar: html::NavBar::PROJECTS,
|
|
|
|
|
};
|
2024-03-24 10:45:16 -04:00
|
|
|
html::HtmlTemplate(template)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "projects.html")]
|
2024-03-24 15:12:36 -04:00
|
|
|
struct ProjectsTemplate {
|
|
|
|
|
active_navbar: &'static str,
|
|
|
|
|
}
|
2024-03-24 10:45:16 -04:00
|
|
|
|
|
|
|
|
async fn now() -> impl IntoResponse {
|
2024-03-24 15:12:36 -04:00
|
|
|
let template = NowTemplate {
|
|
|
|
|
active_navbar: html::NavBar::NOW,
|
|
|
|
|
};
|
2024-03-24 10:45:16 -04:00
|
|
|
html::HtmlTemplate(template)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "now.html")]
|
2024-03-24 15:12:36 -04:00
|
|
|
struct NowTemplate {
|
|
|
|
|
active_navbar: &'static str,
|
|
|
|
|
}
|
2024-03-24 10:45:16 -04:00
|
|
|
|
|
|
|
|
async fn about() -> impl IntoResponse {
|
2024-03-24 15:12:36 -04:00
|
|
|
let template = AboutTemplate {
|
|
|
|
|
active_navbar: html::NavBar::ABOUT,
|
|
|
|
|
};
|
2024-03-24 10:45:16 -04:00
|
|
|
html::HtmlTemplate(template)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "about.html")]
|
2024-03-24 15:12:36 -04:00
|
|
|
struct AboutTemplate {
|
|
|
|
|
active_navbar: &'static str,
|
|
|
|
|
}
|
2024-03-24 10:45:16 -04:00
|
|
|
|
|
|
|
|
async fn contact() -> impl IntoResponse {
|
2024-03-24 15:12:36 -04:00
|
|
|
let template = ContactTemplate {
|
|
|
|
|
active_navbar: html::NavBar::CONTACT
|
|
|
|
|
};
|
2024-03-24 10:45:16 -04:00
|
|
|
html::HtmlTemplate(template)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "contact.html")]
|
2024-03-24 15:12:36 -04:00
|
|
|
struct ContactTemplate {
|
|
|
|
|
active_navbar: &'static str,
|
|
|
|
|
}
|