-
Notifications
You must be signed in to change notification settings - Fork 3
/
layout.rs
233 lines (216 loc) · 9.73 KB
/
layout.rs
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use chrono::Utc;
use maud::{html, Markup, PreEscaped, DOCTYPE};
use std::fmt::Display;
use url::Url;
use crate::{content::smart_quotes, GIT_SHA, GIT_SHA_SHORT};
#[derive(Debug)]
pub struct Head {
pub title: String,
pub description: String,
pub url: Url,
pub og_type: OgType,
}
#[allow(dead_code)]
#[derive(Debug, Default)]
pub enum OgType {
#[default]
Website,
Article,
Product,
}
impl Display for OgType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OgType::Website => write!(f, "website"),
OgType::Article => write!(f, "article"),
OgType::Product => write!(f, "product"),
}
}
}
pub struct Context {
head: Head,
content: Markup,
options: Option<Options>,
}
impl Context {
pub fn new(head: Head, content: Markup) -> Self {
Self {
head,
content,
options: None,
}
}
pub fn new_with_options(head: Head, content: Markup, options: Options) -> Self {
Self {
head,
content,
options: Some(options),
}
}
}
#[derive(Debug, Default)]
pub struct Options {
pub is_index: bool,
pub back_link: Option<String>,
}
pub struct Layout {
pub css_hash: String,
pub hot_reload_websocket_port: Option<u16>,
}
impl Layout {
pub fn new(css_hash: impl Into<String>, hot_reload_websocket_port: Option<u16>) -> Self {
Self {
css_hash: css_hash.into(),
hot_reload_websocket_port,
}
}
pub fn render(&self, context: Context) -> Markup {
let head = context.head;
let options = context.options.unwrap_or_default();
html! {
(DOCTYPE)
html lang="en" {
head {
title { (head.title) }
meta charset="utf-8";
meta name="title" content=(smart_quotes(head.title.clone()));
meta name="description" content=(smart_quotes(head.description.clone()));
meta name="author" content="Arne Bahlo";
meta name="theme-color" content="#010101";
meta name="viewport" content="width=device-width,initial-scale=1";
meta property="og:type" content=(head.og_type);
meta property="og:url" content=(head.url);
meta property="og:title" content=(smart_quotes(head.title));
meta property="og:description" content=(smart_quotes(head.description));
link rel="sitemap" href="/sitemap.xml";
// link rel="stylesheet" href=(format!("/main.css?hash={}", self.css_hash));
// link rel="preload" href="/fonts/rebond-grotesque/ESRebondGrotesque-Regular.woff2" as="font" type="font/woff2";
// link rel="preload" href="/fonts/rebond-grotesque/ESRebondGrotesque-Bold.woff2" as="font" type="font/woff2";
// link rel="preload" href="/fonts/rebond-grotesque/ESRebondGrotesque-Italic.woff2" as="font" type="font/woff2";
link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png";
link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png";
link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png";
link rel="manifest" href="/site.webmanifest";
link rel="alternate" type="application/rss+xml" title=(smart_quotes("Arne's Blog")) href="/feed.xml";
link rel="alternate" type="application/rss+xml" title=(smart_quotes("Arne's Weekly")) href="/weekly/feed.xml";
link rel="alternate" type="application/rss+xml" title=(smart_quotes("Arne's Book Reviews")) href="/book-reviews/feed.xml";
link rel="me" href="https://spezi.social/@arne";
link rel="me" href="mailto:hey@arne.me";
link rel="webmention" href="https://webmention.io/arne.me/webmention";
@if let Some(port) = self.hot_reload_websocket_port {
script {
(format!("const port = {}", port))
(PreEscaped(r#"
const socket = new WebSocket("ws://localhost:"+port);
socket.addEventListener("message", (event) => {
console.log(event);
window.location.reload();
});
"#));
}
}
@if options.is_index {
script {
(PreEscaped(r#"
document.addEventListener("DOMContentLoaded", () => {
const version = Math.floor(Math.random() * 3);
console.log(version);
const arne = document.querySelector(".hero__arne");
if (version > 0) {
arne.classList.add("hero__arne--alt-" + version);
}
});
"#))
}
}
}
body {
a.skip-link href="#main" { "Skip to content" }
.sitewrapper {
.top-part {
main #main {
(context.content)
}
br.hidden; // Looks better in HTML-only
aside {
(PreEscaped(include_str!("../../static/arne.svg")))
h1.hero__heading { (smart_quotes("Hej, I'm Arne—")) }
p.hero__subheading {
(smart_quotes("a developer, podcaster & dad based near Frankfurt, Germany."))
}
nav.main-navigation {
ul {
li {
a href="/" { "Home" }
}
li {
a href="/weekly" { "Newsletter" }
}
li {
a href="/book-reviews" { "Library" }
}
li {
a href="/home-screens" { "Home Screens" }
}
}
ul {
li {
a href="/now" { "/now" }
}
li {
a href="/blogroll" { "Blogroll" }
}
li {
a href="/projects" { "Projects" }
}
li {
a href="/contact" { "Contact" }
}
}
}
}
}
br.hidden; // Looks better in HTML-only
footer.footer {
span.footer_copyright {
(PreEscaped("© 2013 – ")) (Utc::now().format("%Y")) " Arne Bahlo"
br;
"Commit "
a href=(format!("https://github.com/bahlo/arne.me/commit/{}", *GIT_SHA)) { (*GIT_SHA_SHORT) };
br;
a.no-underline href="https://firechicken.club/arne/prev" { "←" }
" "
a href="https://firechicken.club" { "Fire Chicken Webring" }
" "
a.no-underline href="https://firechicken.club/arne/next" { "→" }
br;
"Made with ♥ by a human."
}
br;
ul {
li {
a href="/colophon" { "Colophon" }
}
li {
a href="/accessibility" { "Accessibility" }
}
li {
a href="/imprint" { "Imprint" }
}
}
}
.h-card hidden {
span.p-name { "Arne Bahlo" }
img.u-photo src="/arne.svg" {}
a.u-url href="https://arne.me" {}
a.u-email href="mailto:hey@arne.me" {}
p.p-note {
"A developer, podcaster & dad based near Frankfurt, Germany."
}
}
}
}
}
}
}
}