1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
use axum::response::IntoResponse;
use axum::Extension;
use maud::{html, Markup, DOCTYPE};
use crate::db::product::{get_all_specificproducts, ProductMarker, SpecificProduct};
use crate::db::ProductDatabaseHandler;
use crate::error::AppError;
pub async fn home() -> Result<impl IntoResponse, AppError> {
Ok(html!((page("Home".to_string(), Markup::default()))))
}
fn page(page_title: String, content: Markup) -> Markup {
html!(
(head(page_title))
body class="bg-[#eae3d2] text-[#333] dark:bg-[#333] dark:text-[#eae3d2] font-mono text-base" {
(header())
(navbar())
(content)
}
)
}
fn header() -> Markup {
html!(
header {
h1 class="underline decoration-[#601B69] dark:decoration-[#e1b1e7] text-center tracking-widest font-serif p-3 text-xl" {"Vithuran Vishnuthas"}
}
)
}
fn navbar() -> Markup {
html!({
navbar class="p-3 text-sm flex flex-row flex-wrap content-center justify-around decoration-[#eae3d2] tracking-wide" {
a class="hover:underline" href="/" { "Home" }
a class="hover:underline" href="/stories" { "Stories" }
a class="hover:underline" href="/" { "Tools" }
a class="hover:underline" href="/" { "Games" }
}
})
}
fn cards<T: PageBuilder + ProductMarker>(
products: Vec<SpecificProduct<T>>,
category: String,
) -> Markup {
html!(
div class="m-12" {
h1 class="p-6 font-serif text-xl tracking-wider underline decoration-[#601B69] dark:decoration-[#E1B1E7]" { (category) }
div class="grid grid-cols-2 gap-8" {
@for product in products {
(card(product))
}
}
}
)
}
fn card<T: PageBuilder + ProductMarker>(specific_product: SpecificProduct<T>) -> Markup {
html!(
div class="p-9 shadow" {
h2 class="text-[#601B69] dark:text-[#E1B1E7]" {
(specific_product.product.name)
}
div {
(specific_product.product.description)
}
div {
(specific_product.detail.product_specific_card_content())
}
div class="flex flex-row space-x-5 mt-9 text-xs" {
span {"Update: " (specific_product.product.updatedate)}
span {"Upload: " (specific_product.product.uploaddate)}
}
}
)
}
fn head(page_title: String) -> Markup {
html! {
head {
(DOCTYPE)
meta charset="utf-8";
link rel="stylesheet" type="text/css" href="/static/styles.css";
title { (page_title) }
}
}
}
pub async fn build_page<T: Sized + ProductMarker + PageBuilder + ProductDatabaseHandler>(
ctx: Extension<super::ApiContext>,
) -> Result<impl IntoResponse, AppError> {
Ok(html!(
(page(
T::page_title(),
cards(
get_all_specificproducts::<T>(&ctx.pool).await?,
T::page_title()
)
))
))
}
pub trait PageBuilder {
fn page_title() -> String;
fn product_specific_card_content(&self) -> Markup;
}
|