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
|
/*
This file is part of metamuffins website (https://codeberg.org/metamuffin/website)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use crate::blog::rocket_uri_macro_r_blog;
use crate::pages::{
rocket_uri_macro_r_about, rocket_uri_macro_r_contact, rocket_uri_macro_r_pgp_key,
rocket_uri_macro_r_projects, rocket_uri_macro_r_stuff, rocket_uri_macro_r_toggle_css,
};
use crate::source::rocket_uri_macro_r_source;
use crate::uri;
use markup::Render;
use rocket::http::CookieJar;
use rocket::{
http::ContentType,
response::{self, Responder},
Request, Response,
};
use std::io::Cursor;
markup::define! {
ScaffoldImpl<Main: Render>(
title: String,
main: Main,
noimg: bool,
include_css: bool
) {
@markup::doctype()
html[lang="en"] {
head {
title { @title " - " "metamuffin's website" }
meta[name="viewport", content="width=device-width, initial-scale=1.0"];
meta[name="description", content="metamuffin's personal website"]; // TODO
@if *include_css { link[rel="stylesheet", href="/style.css"]; }
}
body {
@if !noimg { img[
src="https://s.metamuffin.org/avatar/default-512.webp",
alt="a muffin with purple glowing regions where a 3d vornoi function using chebychev distance exceeds some threshold",
align="left",
height=80,
width=80,
hspace=10,
]; }
h1 { "metamuffin's personal website" }
nav {
a[href=uri!(r_about())] { "About" } " "
a[href=uri!(r_blog())] { "Blog" } " "
a[href=uri!(r_projects())] { "Projects" } " "
a[href=uri!(r_contact())] { "Contact" } " "
a[href=uri!(r_stuff())] { "Stuff" } " "
a[href="https://codeberg.org/metamuffin"] { "Codeberg" } " "
a[href=uri!(r_pgp_key())] { "PGP-Key" } " "
}
hr;
article { @main }
hr;
footer {
p {
"metamuffin's website; version " @include_str!("../.git/refs/heads/main")[0..10] "; "
"sources available on " a[href=uri!(r_source())] { "this page itself" }
" and on " a[href="https://codeberg.org/metamuffin/website"] { "codeberg" }
}
p { "In case you " i {"really"} " want to, you can enable stylesheets." }
form[action=uri!(r_toggle_css()), method="POST"] {
input[type="submit", value="Toggle CSS (uses a cookie)"];
}
}
}
}
}
}
pub type DynScaffold<'a> = Scaffold<markup::DynRender<'a>>;
pub struct Scaffold<T> {
pub title: String,
pub content: T,
}
impl<'r, Main: Render> Responder<'r, 'static> for Scaffold<Main> {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let jar = async_std::task::block_on(req.guard::<&CookieJar>()).unwrap();
let mut out = String::new();
ScaffoldImpl {
main: self.content,
noimg: self.title == "Source",
title: self.title,
include_css: jar.get("css").map(|v| v.value() == "yes").unwrap_or(false),
}
.render(&mut out)
.unwrap();
Response::build()
.header(ContentType::HTML)
.streamed_body(Cursor::new(out))
.ok()
}
}
|