-
Notifications
You must be signed in to change notification settings - Fork 1
/
views.rs
269 lines (244 loc) · 6.8 KB
/
views.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
use iron::prelude::*;
use maud::{Markup, PreEscaped, Render};
use pulldown_cmark;
use user::User;
static STYLES: &'static str = r#"
html {
box-sizing: border-box;
font: 100%/1.5 "Liberation Serif", "Times New Roman", serif;
background: linear-gradient(to bottom, #445 0%, #001 100%);
}
@media (min-width: 450px) {
html {
font-size: 125%;
}
}
@media (min-width: 750px) {
html {
font-size: 150%;
}
}
input, button {
font-size: 1rem;
line-height: 1.5;
}
* {
box-sizing: inherit;
}
body {
margin: 0 auto;
max-width: 30rem;
min-height: 100vh;
padding: 0.5rem 1.5rem;
box-shadow: 0 0 0 8px #ccc, 0 0 0 16px #999, 0 0 0 20px #666;
background: #fff;
}
a {
text-decoration: none;
color: #910;
}
a:hover, a:focus, a:active {
text-shadow: 0 0 2px #fff, 0 0 8px #d60;
}
h1 {
/* A E S T H E T I C */
margin: 0 0 1rem;
white-space: nowrap;
font-family: "Comic Sans MS", sans-serif;
font-size: 1.75rem;
letter-spacing: 0.5rem;
}
@media (min-width: 600px) {
h1 {
font-size: 3rem;
letter-spacing: 0.75rem;
}
}
h1 a {
color: #f90;
text-transform: uppercase;
text-shadow: 2px 2px #000, -2px -2px #faa;
transition: text-shadow 0.2s;
}
h1 a:hover, h1 a:focus, h1 a:active {
text-shadow: 16px 16px #000, -16px -16px #faa;
transition: text-shadow 0.2s;
}
.karkinos {
font-family: "Comic Sans MS", sans-serif;
}
#q {
width: 100%;
padding: 0.25rem 0.5rem;
border: 1px solid #000;
box-shadow: 0 0 0 0 #f90, 0 0 0 0 #666;
transition: box-shadow 0.2s;
}
#q:focus {
border-color: #f90;
box-shadow: -2px -2px 0 2px #f90, 2px 2px 0 3px #666;
transition: box-shadow 0.2s;
}
table {
border-spacing: 0.5rem;
}
th {
text-align: right;
vertical-align: top;
}
"#;
pub fn layout(r: &Request, title: Option<&str>, body: Markup) -> Markup {
let url = r.url.clone().into_generic_url();
html! {
(PreEscaped("<!DOCTYPE html>"))
html {
meta charset="utf-8" /
title {
@if let Some(title) = title {
(title) " - "
}
"Karkinos"
}
meta name="viewport" content="width=device-width" /
style (PreEscaped(STYLES))
body {
h1 a href="/" "🦀Karkinos"
@if let Some(title) = title {
h2 a href=(url.path()) title="Link to this page" (title)
}
(body)
}
}
}
}
pub fn home(r: &Request) -> Markup {
layout(r, None, html! {
form action=(url_for!(r, "search")) {
input name="q" id="q" type="search" placeholder="Enter a username" /
}
script (PreEscaped("document.getElementById('q').select()"))
p {
span.karkinos "KARKINOS"
" is a database of people interested in the "
a href="https://www.rust-lang.org" "Rust programming language"
". It uses the same data as "
a href="http://rustaceans.org" "rustaceans.org"
", but presents it through a different interface."
}
p "I created Karkinos for these reasons:"
ul {
li "To provide access for users who browse with JavaScript disabled;"
li "To rewrite the backend in Rust (instead of Node.js);"
li {
"As a proving ground for my template engine, "
a href="https://github.com/lfairy/maud" "Maud"
";"
}
li "To screw around with CSS (this is the most important reason)."
}
p {
"Karkinos is named after a very special "
a href="https://en.wikipedia.org/wiki/Cancer_(constellation)#Names" "giant crab"
"."
}
p {
"The source code for this site can be found on "
a href="https://github.com/lfairy/karkinos" "GitHub"
"."
}
})
}
pub fn not_found(r: &Request) -> Markup {
layout(r, Some("Not found"), html! {
p {
"The page at "
strong (r.url)
" could not be found."
}
p a href="/" "‹ Back to home page"
})
}
pub fn user(r: &Request, id: &str, user: &User) -> Markup {
let title = if let Some(ref name) = user.name {
format!("{} ({})", name, id)
} else {
id.to_string()
};
layout(r, Some(&title), html! {
table {
@if let Some(ref nick) = user.irc {
tr {
th "IRC"
td {
(nick)
@if !user.irc_channels.is_empty() {
" on "
@for (i, channel) in user.irc_channels.iter().enumerate() {
@if i > 0 { ", " }
a href={ "irc://irc.mozilla.org/" (channel) } {
"#" (channel)
}
}
}
}
}
}
@if let Some(ref x) = user.discourse {
tr {
th "Discourse"
td a href={ "https://users.rust-lang.org/users/" (x) } (x)
}
}
@if let Some(ref x) = user.reddit {
tr {
th "Reddit"
td a href={ "https://reddit.com/user/" (x) } (x)
}
}
@if let Some(ref x) = user.twitter {
tr {
th "Twitter"
td a href={ "https://twitter.com/" (x) } (x)
}
}
@if let Some(ref x) = user.website {
tr {
th "Website"
td a href=(x) (x)
}
}
@if let Some(ref x) = user.blog {
tr {
th "Blog"
td a href=(x) (x)
}
}
@if let Some(ref x) = user.email {
tr {
th "Email"
td a href={ "mailto:" (x) } (x)
}
}
}
@if let Some(ref x) = user.notes {
div.notes (Markdown(x))
}
})
}
pub fn user_not_found(r: &Request, id: &str) -> Markup {
layout(r, Some(id), html! {
p {
"The user "
strong (id)
" could not be found."
}
p a href="/" "‹ Back to home page"
})
}
struct Markdown<'a>(&'a str);
impl<'a> Render for Markdown<'a> {
fn render_to(&self, buffer: &mut String) {
let parser = pulldown_cmark::Parser::new(self.0);
pulldown_cmark::html::push_html(buffer, parser);
}
}