blob: 6da30fc1624c1c937b2e018a078f8bf9a1f2ca52 (
plain)
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
|
use anyhow::{Context, Result};
use maud::{html, Markup, DOCTYPE};
use serde::Deserialize;
#[derive(Deserialize)]
struct Data {
stories: Vec<Story>,
}
impl Data {
fn render_stories(self) -> Markup {
html!(
@for story in self.stories {
(story.render_as_card())
}
)
}
}
#[derive(Deserialize)]
struct Story {
name: String,
description: String,
}
impl Story {
fn render_as_card(self) -> Markup {
html!(card {
span { (self.name) }
span { (self.description) }
})
}
}
fn render_head(page_title: &str) -> Markup {
html!(
head {
(DOCTYPE)
meta charset="utf-8";
meta name="viewport" content="width=device-width,initial-scale=1";
title { (page_title) }
}
)
}
fn render_navigation() -> Markup {
html!(
div class="navbar" {
header {
h1 {
"V2 Tales";
}
}
nav {
a href="" {
"HOME";
}
a href="" {
"STORIES";
}
}
}
)
}
fn style() -> Markup {
html!(
style {
"""
* {
padding: 0;
margin: 0;
}
h1 {
padding: 0.3rem;
letter-spacing: 0.8rem;
font-size: 1.5rem;
color: #0d234adb;
display: flex;
justify-content: center;
align-items: center;
gap: 2rem;
}
h2 {
font-size: 2rem;
margin-bottom: 2rem;
color: #0d234adb;
}
body {
margin: 2rem 1rem;
background-color: #ffc994;
text-align: center;
}
hr {
margin: 1rem;
}
img {
max-width: 3rem;
max-height: 3rem;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 3rem;
}
nav {
display: flex;
justify-content: space-around;
width: 50%;
a {
text-decoration: none;
color: #0d234adb;
&:hover {
text-decoration: underline;
}
}
}
"""
}
)
}
fn main() -> Result<()> {
let data_file_content =
std::fs::read_to_string("data.toml").with_context(|| "Failed to read data.toml")?;
let data: Data = toml::from_str(&data_file_content)?;
let stories_html = html!((render_head("Stories - V2 Tales"))(style())(
render_navigation()
)(data.render_stories()));
std::fs::write("dist/stories.html", stories_html.into_string())
.with_context(|| "Failed to write dist/stories.html")?;
Ok(())
}
|