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
//! Built-in themes for Zorto.
//!
//! Themes provide default templates and SCSS that ship with the Zorto binary.
//! A site can select a theme via `theme = "dkdc"` in `config.toml`. Local
//! `templates/` and `sass/` files always override theme defaults.
//!
//! Each theme is gated behind a Cargo feature (`theme-dkdc`, `theme-light`,
//! `theme-dark`). All are enabled by default. In Python builds all themes are
//! always included.
/// A built-in theme.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Theme {
/// Violet/cyan dark-default theme with animations. The dkdc brand theme.
#[cfg(feature = "theme-dkdc")]
Dkdc,
/// Clean light-default theme. No animations.
#[cfg(feature = "theme-light")]
Light,
/// Clean dark-default theme. No animations.
#[cfg(feature = "theme-dark")]
Dark,
/// Blue/green dark-default theme with animations. The zorto brand theme.
#[cfg(feature = "theme-zorto")]
Zorto,
}
impl Theme {
/// Parse a theme name from a string.
///
/// Returns `None` if the name is unknown or the corresponding feature is
/// not enabled.
pub fn from_name(name: &str) -> Option<Self> {
match name {
#[cfg(feature = "theme-dkdc")]
"dkdc" => Some(Self::Dkdc),
#[cfg(feature = "theme-light")]
"light" => Some(Self::Light),
#[cfg(feature = "theme-dark")]
"dark" => Some(Self::Dark),
#[cfg(feature = "theme-zorto")]
"zorto" => Some(Self::Zorto),
_ => None,
}
}
/// List all available theme names (only those whose features are enabled).
#[allow(unused_mut, clippy::vec_init_then_push)]
pub fn available() -> Vec<&'static str> {
let mut names = Vec::new();
#[cfg(feature = "theme-dkdc")]
names.push("dkdc");
#[cfg(feature = "theme-light")]
names.push("light");
#[cfg(feature = "theme-dark")]
names.push("dark");
#[cfg(feature = "theme-zorto")]
names.push("zorto");
names
}
/// Get all template files for this theme as `(name, content)` pairs.
///
/// Template names use forward slashes (e.g. `"macros/post.html"`).
#[allow(unreachable_patterns)]
pub fn templates(&self) -> Vec<(&'static str, &'static str)> {
match self {
#[cfg(feature = "theme-dkdc")]
Self::Dkdc => vec![
(
"base.html",
include_str!("../themes/dkdc/templates/base.html"),
),
(
"page.html",
include_str!("../themes/dkdc/templates/page.html"),
),
(
"section.html",
include_str!("../themes/dkdc/templates/section.html"),
),
(
"index.html",
include_str!("../themes/dkdc/templates/index.html"),
),
(
"404.html",
include_str!("../themes/dkdc/templates/404.html"),
),
(
"macros/post.html",
include_str!("../themes/dkdc/templates/macros/post.html"),
),
],
#[cfg(feature = "theme-light")]
Self::Light => vec![
(
"base.html",
include_str!("../themes/light/templates/base.html"),
),
(
"page.html",
include_str!("../themes/light/templates/page.html"),
),
(
"section.html",
include_str!("../themes/light/templates/section.html"),
),
(
"index.html",
include_str!("../themes/light/templates/index.html"),
),
(
"404.html",
include_str!("../themes/light/templates/404.html"),
),
(
"macros/post.html",
include_str!("../themes/light/templates/macros/post.html"),
),
],
#[cfg(feature = "theme-dark")]
Self::Dark => vec![
(
"base.html",
include_str!("../themes/dark/templates/base.html"),
),
(
"page.html",
include_str!("../themes/dark/templates/page.html"),
),
(
"section.html",
include_str!("../themes/dark/templates/section.html"),
),
(
"index.html",
include_str!("../themes/dark/templates/index.html"),
),
(
"404.html",
include_str!("../themes/dark/templates/404.html"),
),
(
"macros/post.html",
include_str!("../themes/dark/templates/macros/post.html"),
),
],
#[cfg(feature = "theme-zorto")]
Self::Zorto => vec![
(
"base.html",
include_str!("../themes/zorto/templates/base.html"),
),
(
"page.html",
include_str!("../themes/zorto/templates/page.html"),
),
(
"section.html",
include_str!("../themes/zorto/templates/section.html"),
),
(
"index.html",
include_str!("../themes/zorto/templates/index.html"),
),
(
"404.html",
include_str!("../themes/zorto/templates/404.html"),
),
(
"macros/post.html",
include_str!("../themes/zorto/templates/macros/post.html"),
),
],
_ => vec![],
}
}
/// Get all SCSS files for this theme as `(filename, content)` pairs.
#[allow(unreachable_patterns)]
pub fn scss(&self) -> Vec<(&'static str, &'static str)> {
match self {
#[cfg(feature = "theme-dkdc")]
Self::Dkdc => vec![("style.scss", include_str!("../themes/dkdc/sass/style.scss"))],
#[cfg(feature = "theme-light")]
Self::Light => vec![(
"style.scss",
include_str!("../themes/light/sass/style.scss"),
)],
#[cfg(feature = "theme-dark")]
Self::Dark => vec![("style.scss", include_str!("../themes/dark/sass/style.scss"))],
#[cfg(feature = "theme-zorto")]
Self::Zorto => vec![(
"style.scss",
include_str!("../themes/zorto/sass/style.scss"),
)],
_ => vec![],
}
}
}