-
Notifications
You must be signed in to change notification settings - Fork 0
/
haunt.scm
382 lines (345 loc) · 11 KB
/
haunt.scm
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
(use-modules (haunt asset)
(haunt builder blog)
(haunt builder atom)
(haunt builder assets)
(haunt html)
(haunt page)
(haunt post)
(haunt reader)
(haunt reader commonmark)
(haunt site)
(haunt utils)
(commonmark)
(syntax-highlight)
(syntax-highlight scheme)
(syntax-highlight xml)
(syntax-highlight c)
(sxml match)
(sxml transform)
(texinfo)
(texinfo html)
(srfi srfi-1)
(srfi srfi-19)
(ice-9 rdelim)
(ice-9 regex)
(ice-9 match)
(web uri))
(define (date year month day)
"Create a SRFI-19 date for the given YEAR, MONTH, DAY"
(let ((tzoffset (tm:gmtoff (localtime (time-second (current-time))))))
(make-date 0 0 0 0 day month year tzoffset)))
(define (stylesheet name)
`(link (@ (rel "stylesheet")
(href ,(string-append "/css/" name ".css")))))
(define* (anchor content #:optional (uri content))
`(a (@ (href ,uri)) ,content))
(define %cc-by-sa-link
'(a (@ (href "https://creativecommons.org/licenses/by-sa/4.0/"))
"Creative Commons Attribution Share-Alike 4.0 International"))
(define %cc-by-sa-button
'(a (@ (class "cc-button")
(href "https://creativecommons.org/licenses/by-sa/4.0/"))
(img (@ (src "https://licensebuttons.net/l/by-sa/4.0/80x15.png")))))
(define (link name uri)
`(a (@ (href ,uri)) ,name))
(define* (centered-image url #:optional alt)
`(img (@ (class "centered-image")
(src ,url)
,@(if alt
`((alt ,alt))
'()))))
(define (first-paragraph post)
(let loop ((sxml (post-sxml post))
(result '()))
(match sxml
(() (reverse result))
((or (('p ...) _ ...) (paragraph _ ...))
(reverse (cons paragraph result)))
((head . tail)
(loop tail (cons head result))))))
(define scm-pw-theme
(theme #:name "scm-pw"
#:layout
(lambda (site title body)
`((doctype "html")
(head
(meta (@ (charset "utf-8")))
(title ,(string-append title " — " (site-title site)))
,(stylesheet "reset")
,(stylesheet "fonts")
,(stylesheet "scm"))
(body
(div (@ (class "container"))
(div (@ (class "nav"))
(ul (li ,(link "'(SCM.PW)" "/"))
(li (@ (class "fade-text")) " ")
(li ,(link "About" "/about.html"))
(li ,(link "Blog" "/index.html"))
(li ,(link "Learning" "/learning.html"))
(li ,(link "Contributions" "/contributions.html"))
(li ,(link "Media" "/media.html")))))
(div (@ (class "container"))
(div (@ (class "yav"))
(ul
(li (@ (class "fade-text")) " ")
(li ,(link "C" "/c.html"))
(li ,(link "Common Lisp" "/common-lisp.html"))
(li ,(link "Coq" "/coq.html"))
(li ,(link "F#" "/fsharp.html"))
(li ,(link "F*" "/fstar.html"))
(li ,(link "Haskell" "/haskell.html"))
(li ,(link "OCaml" "/ocaml.html"))
(li ,(link "Rust" "/rust.html"))
(li ,(link "Scheme" "/scheme.html"))))
,body
(footer (@ (class "text-center"))
(p (@ (class "copyright"))
"©2019 Brett Gilio"
,%cc-by-sa-button)
(p "Made with "
(a (@ (href "https://schemers.org/"))
"λ")
" using "
(a (@ (href "https://gnu.org/software/guile"))
"Guile Scheme")
"."))))))
#:post-template
(lambda (post)
`((h1 (@ (class "title")),(post-ref post 'title))
(div (@ (class "author")) ; XXX: fix class, and spacing
,(post-ref post 'author)
" — " ; Em dash, long dash.
,(date->string (post-date post)
"~B ~d, ~Y"))
(div (@ (class "post"))
,(post-sxml post))))
#:collection-template
(lambda (site title posts prefix)
(define (post-uri post)
(string-append "/" (or prefix "")
(site-post-slug site post) ".html"))
`((h1 ,title)
,(map (lambda (post)
(let ((uri (string-append "/"
(site-post-slug site post)
".html")))
`(div (@ (class "summary"))
(h2 (a (@ (href ,uri))
,(post-ref post 'title)))
(div (@ (class "date"))
,(date->string (post-date post)
"~B ~d, ~Y"))
(div (@ (class "post"))
,(first-paragraph post))
(div (@ (class "read"))
(a (@ (href ,uri)) "read more ➔")))))
posts)))))
(define %collections
`(("Recent Entries" "index.html" ,posts/reverse-chronological)))
(define parse-lang
(let ((rx (make-regexp "-*-[ ]+([a-z]*)[ ]+-*-")))
(lambda (port)
(let ((line (read-line port)))
(match:substring (regexp-exec rx line) 1)))))
(define (maybe-highlight-code lang source)
(let ((lexer (match lang
('scheme lex-scheme)
('xml lex-xml)
('c lex-c)
(_ #f))))
(if lexer
(highlights->sxml (highlight lexer source))
source)))
(define (sxml-identity . args) args)
(define (highlight-code . tree)
(sxml-match tree
((code (@ (class ,class) . ,attrs) ,source)
(let ((lang (string->symbol
(string-drop class (string-length "language-")))))
`(code (@ ,@attrs)
,(maybe-highlight-code lang source))))
(,other other)))
(define (highlight-scheme code)
`(pre (code ,(highlights->sxml (highlight lex-scheme code)))))
(define (raw-snippet code)
`(pre (code ,(if (string? code) code (read-string code)))))
;; Markdown doesn't support video, so let's hack around that! Find
;; <img> tags with a ".webm" source and substitute a <video> tag.
(define (media-hackery . tree)
(sxml-match tree
((img (@ (src ,src) . ,attrs) . ,body)
(if (string-suffix? ".webm" src)
`(video (@ (src ,src) (controls "true"),@attrs) ,@body)
tree))))
(define %commonmark-rules
`((code . ,highlight-code)
(img . ,media-hackery)
(*text* . ,(lambda (tag str) str))
(*default* . ,sxml-identity)))
(define (post-process-commonmark sxml)
(pre-post-order sxml %commonmark-rules))
(define commonmark-reader*
(make-reader (make-file-extension-matcher "md")
(lambda (file)
(call-with-input-file file
(lambda (port)
(values (read-metadata-headers port)
(post-process-commonmark
(commonmark->sxml port))))))))
(define (static-page title file-name body)
(lambda (site posts)
(make-page file-name
(with-layout scm-pw-theme site title body)
sxml->html)))
(define c-page
(static-page
"C"
"c.html"
`((h1 "C")
(p (i ("Coming soon..."))))))
(define haskell-page
(static-page
"Haskell"
"haskell.html"
`((h1 "Haskell")
(p (i ("Coming soon..."))))))
(define coq-page
(static-page
"Coq"
"coq.html"
`((h1 "Coq")
(p (i ("Coming soon..."))))))
(define fsharp-page
(static-page
"F#"
"fsharp.html"
`((h1 "F#")
(p (i ("Coming soon..."))))))
(define fstar-page
(static-page
"F*"
"fstar.html"
`((h1 "F*")
(p (i ("Coming soon..."))))))
(define common-lisp-page
(static-page
"Common Lisp"
"common-lisp.html"
`((h1 "Common Lisp")
(p (i ("Coming soon..."))))))
(define ocaml-page
(static-page
"OCaml"
"ocaml.html"
`((h1 "OCaml")
(p (i ("Coming soon..."))))))
(define rust-page
(static-page
"Rust"
"rust.html"
`((h1 "Rust")
(p (i ("Coming soon..."))))))
(define scheme-page
(static-page
"Scheme"
"scheme.html"
`((h1 "Scheme")
(p (i ("Coming soon..."))))))
(define learning-page
(static-page
"Learning"
"learning.html"
`((h1 "Learning")
(p (i ("Coming soon..."))))))
(define contributions-page
(static-page
"Contributions"
"contributions.html"
`((h1 "Contributions")
(p (i ("Coming soon..."))))))
(define media-page
(static-page
"Media"
"media.html"
`((h1 "Media")
(p (i ("Coming soon..."))))))
(define projects-page
(static-page
"Projects"
"projects.html"
`((h1 "Projects")
(p (i ("Coming soon..."))))))
(define brett-cv-page
(static-page
"Brett Gilio, C.V."
"cv.html"
`((div (@ (class "resume-name"))
(h2 "Brett M. Gilio")
(div (@ (class "resume-sub-name"))
"5309 Michigan Ave")
(div (@ (class "resume-sub-name"))
"Kansas City, MO 64130"))
(div (@ (class "resume-contact"))
"M: +1 816(668-9215) | E: brettg@posteo.net")
(div (@ (class "resume-update"))
"Last Updated: May 5th, 2019")
(div (@ (class "resume-category"))
"Education")
(div (@ (class "resume-education"))
(span (@ (class "floatleft"))
"University of Missouri - Kansas City")
(span (@ (class "floatright"))
"Add years"))
(br)
(div (@ (class "resume-education"))
(span (@ (class "educ"))
"Bachelor of Science - Biology")
(br)
(span (@ (class "educit"))
"Minor in Chemistry"))
(br)
(div (@ (class "resume-education"))
(span (@ (class "floatleft"))
"University of Missouri - Kansas City")
(span (@ (class "floatright"))
"Add years"))
(br)
(div (@ (class "resume-education"))
(span (@ (class "educ"))
"Bachelor of Music - Music Composition"))
(div (@ (class "resume-category"))
"Work Experience")
(div (@ (class "resume-category"))
"Research Experience"))))
(site #:title "'(SCM.PW)"
#:domain "scm.pw"
#:default-metadata
'((author . "Brett Gilio")
(email . "brettg@posteo.net"))
#:readers (list commonmark-reader*)
#:builders (list (blog #:theme scm-pw-theme #:collections %collections)
(atom-feed)
(atom-feeds-by-tag)
about-page
brett-cv-page
projects-page
c-page
common-lisp-page
coq-page
fsharp-page
fstar-page
haskell-page
ocaml-page
rust-page
scheme-page
learning-page
contributions-page
media-page
;(static-directory "js")
(static-directory "css")
(static-directory "fonts")
(static-directory "images")
(static-directory "videos")
(static-directory "src")
(static-directory "manuals")
(static-directory "keys")))