Cleaning up routers
This commit is contained in:
parent
c13f34f7c5
commit
ba8f641a74
3 changed files with 39 additions and 26 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::database::data::Article;
|
use crate::database::data::Article;
|
||||||
use crate::html;
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Extension, Path},
|
extract::{Extension, Path},
|
||||||
|
|
@ -9,14 +8,27 @@ use axum::{
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::root::AppState;
|
use super::{root::AppState, HtmlTemplate, NavBar};
|
||||||
|
|
||||||
pub fn get_router() -> Router {
|
pub fn get_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(html::root::blog))
|
.route("/", get(blog))
|
||||||
.route("/:article", get(article))
|
.route("/:article", get(article))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn blog() -> impl IntoResponse {
|
||||||
|
let template = BlogTemplate {
|
||||||
|
active_navbar: NavBar::BLOG,
|
||||||
|
};
|
||||||
|
HtmlTemplate(template)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "blog.html")]
|
||||||
|
struct BlogTemplate {
|
||||||
|
active_navbar: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "Article.html")]
|
#[template(path = "Article.html")]
|
||||||
struct ArticleTemplate {
|
struct ArticleTemplate {
|
||||||
|
|
@ -37,7 +49,7 @@ async fn article(
|
||||||
Err(_) => panic!("Not an article at all!!!!"),
|
Err(_) => panic!("Not an article at all!!!!"),
|
||||||
};
|
};
|
||||||
let template = ArticleTemplate {
|
let template = ArticleTemplate {
|
||||||
active_navbar: html::NavBar::BLOG,
|
active_navbar: NavBar::BLOG,
|
||||||
content: article.content,
|
content: article.content,
|
||||||
previous: match article.previous {
|
previous: match article.previous {
|
||||||
Some(a) => a,
|
Some(a) => a,
|
||||||
|
|
@ -48,5 +60,5 @@ async fn article(
|
||||||
None => "".to_string(),
|
None => "".to_string(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
html::HtmlTemplate(template)
|
HtmlTemplate(template)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,35 @@
|
||||||
use crate::html;
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
|
use super::{HtmlTemplate, NavBar};
|
||||||
|
|
||||||
pub fn get_router() -> Router {
|
pub fn get_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(html::root::projects))
|
.route("/", get(projects))
|
||||||
.route("/archserver", get(archserver))
|
.route("/archserver", get(archserver))
|
||||||
.route("/tak", get(tak))
|
.route("/tak", get(tak))
|
||||||
.route("/ed", get(ed))
|
.route("/ed", get(ed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn projects() -> impl IntoResponse {
|
||||||
|
let template = ProjectsTemplate {
|
||||||
|
active_navbar: NavBar::PROJECTS,
|
||||||
|
};
|
||||||
|
HtmlTemplate(template)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "projects.html")]
|
||||||
|
struct ProjectsTemplate {
|
||||||
|
active_navbar: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
async fn archserver() -> impl IntoResponse {
|
async fn archserver() -> impl IntoResponse {
|
||||||
let template = ArchServerTemplate {
|
let template = ArchServerTemplate {
|
||||||
active_navbar: html::NavBar::PROJECTS
|
active_navbar: NavBar::PROJECTS
|
||||||
};
|
};
|
||||||
html::HtmlTemplate(template)
|
HtmlTemplate(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
|
@ -26,9 +40,9 @@ struct ArchServerTemplate {
|
||||||
|
|
||||||
async fn tak() -> impl IntoResponse {
|
async fn tak() -> impl IntoResponse {
|
||||||
let template = TakTemplate {
|
let template = TakTemplate {
|
||||||
active_navbar: html::NavBar::PROJECTS
|
active_navbar: NavBar::PROJECTS
|
||||||
};
|
};
|
||||||
html::HtmlTemplate(template)
|
HtmlTemplate(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
|
@ -39,9 +53,9 @@ struct TakTemplate {
|
||||||
|
|
||||||
async fn ed() -> impl IntoResponse {
|
async fn ed() -> impl IntoResponse {
|
||||||
let template = EdgeDetectionTemplate {
|
let template = EdgeDetectionTemplate {
|
||||||
active_navbar: html::NavBar::PROJECTS
|
active_navbar: NavBar::PROJECTS
|
||||||
};
|
};
|
||||||
html::HtmlTemplate(template)
|
HtmlTemplate(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
|
|
||||||
|
|
@ -48,19 +48,6 @@ struct HomeTemplate {
|
||||||
active_navbar: &'static str,
|
active_navbar: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn blog() -> impl IntoResponse {
|
|
||||||
let template = BlogTemplate {
|
|
||||||
active_navbar: NavBar::BLOG,
|
|
||||||
};
|
|
||||||
HtmlTemplate(template)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Template)]
|
|
||||||
#[template(path = "blog.html")]
|
|
||||||
struct BlogTemplate {
|
|
||||||
active_navbar: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn projects() -> impl IntoResponse {
|
pub async fn projects() -> impl IntoResponse {
|
||||||
let template = ProjectsTemplate {
|
let template = ProjectsTemplate {
|
||||||
active_navbar: NavBar::PROJECTS,
|
active_navbar: NavBar::PROJECTS,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue