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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
use axum::response::IntoResponse;
use maud::{html, Markup, DOCTYPE};
use crate::db::product::{Product, ProductMarker};
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.specific.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>(
) -> Result<impl IntoResponse, AppError> {
Ok(html!(
(page(T::page_title(), cards(T::products(), T::page_title())))
))
}
pub trait PageBuilder {
fn page_title() -> String;
fn products() -> Vec<SpecificProduct<Self>>
where
Self: Sized + ProductMarker;
fn product_specific_card_content(&self) -> Markup;
}
// TODO: Remove after first implementation
#[derive(Hash, PartialEq, Eq)]
pub struct DummyProduct {
dummy: String,
}
impl PageBuilder for DummyProduct {
fn page_title() -> String {
"Dummy Products".to_string()
}
fn products() -> Vec<SpecificProduct<Self>>
where
Self: Sized,
{
let product1 = Product {
id: 0,
name: "Willensfreiheit in Ketten".to_string(),
description:
"Nach der Flucht seines Bruders, verzweifelt Fahim an der Existenz der Willensfreiheit."
.to_string(),
uploaddate: 1,
updatedate: 1,
};
let product2 = Product {
id: 1,
name: "Aufbruch und Abbruch".to_string(),
description: "Ein frischer Absolvent muss sich vor der ersten Quest nur noch bei der Gilde für Heilkünstler anmelden.".to_string(),
uploaddate: 1,
updatedate: 1,
};
let product3 = Product {
id: 2,
name: "Mit gutem Gewissen".to_string(),
description: "Ein frischer Absolvent muss sich vor der ersten Quest nur noch bei der Gilde für Heilkünstler anmelden.".to_string(),
uploaddate: 1,
updatedate: 1,
};
let test1 = DummyProduct {
dummy: "/".to_string(),
};
let test2 = DummyProduct {
dummy: "/".to_string(),
};
let test3 = DummyProduct {
dummy: "/".to_string(),
};
let specific1 = SpecificProduct {
product: product1,
specific: test1,
};
let specific2 = SpecificProduct {
product: product2,
specific: test2,
};
let specific3 = SpecificProduct {
product: product3,
specific: test3,
};
vec![specific1, specific2, specific3]
}
fn product_specific_card_content(&self) -> Markup {
html!(
a class="mt-9 text-[#601B69] dark:text-[#E1B1E7]" href=(self.dummy) {
"Link"
}
)
}
}
impl ProductMarker for DummyProduct {}
// TODO: Refactoring
pub struct SpecificProduct<T: ProductMarker> {
product: Product,
specific: T,
}
|