-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaunt.scm
374 lines (333 loc) · 13.4 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
(use-modules (haunt artifact)
(haunt asset)
(haunt builder blog)
(haunt builder atom)
(haunt builder assets)
(haunt html)
(haunt post)
(haunt reader)
(haunt reader commonmark)
(haunt site)
(web uri)
(ice-9 match)
(migalmoreno reader dir-tagging)
(migalmoreno reader org-mode)
(srfi srfi-1)
(srfi srfi-19)
(srfi srfi-26)
(sxml simple))
(define (org-string->date str)
"Convert STR, a string in Org format, into a SRFI-19 date object."
(catch 'misc-error
(lambda () (string->date str "<~Y-~m-~d ~a ~H:~M>"))
(lambda (key . parameters) (string->date str "<~Y-~m-~d ~a>"))))
(register-metadata-parser! 'date org-string->date)
;;
;; Components/Utilities
;;
(define (static-page title filename body)
(lambda (site posts)
(serialized-artifact filename
(with-layout %blog-theme site title body)
sxml->html)))
(define* (anchor label url #:key external? extra-classes (extra-attributes '()))
`(a (@ (href ,url)
,@(if extra-classes
`((class ,(string-append "main__anchor " extra-classes)))
'((class "main__anchor")))
,@(append extra-attributes
(if external?
'((rel noopener)
(target _blank))
'())))
,label))
(define (bulleted-list entries)
`(ul (@ (class "list"))
,@(map (lambda (i)
`(li (@ (class "list-item--type-bulleted")) ,i))
entries)))
(define (blog-entries site posts)
(if (> (length posts) 0)
(map (lambda (post)
`(a (@ (class "post-item")
(href ,(blog-post-uri post)))
(span (@ (class "post-item__title"))
,(post-title post))
(span (@ (class "post-item__date"))
,(date->string* (post-date post)))))
posts)
'((p "No blog posts found."))))
(define (portfolio-entries site projects)
(map (lambda (project)
`(div (@ (class "project-item"))
(div (@ (class "project-item__wrapper"))
(div (@ (class "project-item__heading"))
(a (@ (class "project-item__title")
(href ,(portfolio-post-uri project)))
,(post-title project)))
(div (@ (class "project-item__synopsis"))
(span ,(post-ref project 'synopsis))))
(ul (@ (class "tags"))
,@(map (lambda (tag)
`(li (@ (class "tag")) ,tag))
(post-ref project 'tags)))))
projects))
(define* (stylesheet name #:key local?)
`(link (@ (rel "stylesheet")
(href ,(if local?
(string-append "/assets/css/" name ".css")
name)))))
(define (script name)
`(script (@ (type "text/javascript")
(src ,(string-append "/assets/js/" name ".js")))))
(define (post-uri post prefix)
(string-append prefix "/" (post-slug post) ".html"))
(define %blog-prefix "/blog")
(define %portfolio-prefix "/projects")
(define (blog-post-uri post) (post-uri post %blog-prefix))
(define (portfolio-post-uri post) (post-uri post %portfolio-prefix))
;;
;; Defaults
;;
(define %domain "migalmoreno.com")
(define %email "[email protected]")
(define %username "migalmoreno")
(define %fullname "Miguel Ángel Moreno")
(define* (logo
#:key
(viewBox "0 0 100 100")
(fill "var(--blue-warmer)")
(height 20)
(width 20))
`(svg (@ (xmlns "http://www.w3.org/2000/svg")
(viewBox ,viewBox)
(fill "none")
(stroke ,fill)
(height ,height)
(width ,width)
(stroke-width "8")
(stroke-linecap "round"))
(polyline
(@ (fill "none")
(points "25,35 10,50 25,65")))
(line (@ (x1 "60") (y1 "20") (x2 "40") (y2 "80")))
(polyline
(@ (fill "none")
(points "75,35 90,50 75,65")))))
;;
;; Layouts
;;
(define navbar
`(header (@ (class "navbar"))
(nav (@ (class "navbar__nav"))
(input (@ (class "navbar__mobile-menu")
(type "checkbox") (id "mobile-menu")))
(div (@ (class "navbar__images"))
,(anchor `(span (@ (class "navbar__logo"))
,(logo)
,%fullname)
"/" #:extra-classes "navbar__link")
(label (@ (class "navbar__menu-icon") (for "mobile-menu"))
(span (@ (class "menu-icon")))))
(ul (@ (class "navbar__menu"))
,@(map (lambda (a)
`(li (@ (class "menu-item"))
,(anchor (car a) (cdr a)
#:extra-classes "menu-item__link")))
'(("Home" . "/")
("Projects" . "/projects")
("Blog" . "/blog")
("Contact" . "/contact.html")))))))
(define (base-layout site title body)
`((doctype "html")
(html
(head
(meta (@ (charset "utf-8")))
(meta (@ (name "viewport")
(content "width=device-width,initial-scale=1")))
(title ,(string-append (site-title site) " - " title))
(link
(@ (rel "icon")
(type "image/svg+xml")
(href ,(string-append
"data:image/svg+xml,"
(uri-encode
(with-output-to-string
(lambda ()
(sxml->xml (logo #:fill "#c4c4c4")))))))))
,(stylesheet "main" #:local? #t))
(body
,navbar
(div (@ (class "body-container"))
(main (@ (class "main")) ,body)
(footer (@ (class "footer"))
(div (@ (class "footer__wrapper"))
,(format #f "© 2024 ~a" %fullname))))))))
;;
;; Templates/themes
;;
(define (post-template post)
`((div (@ (class "post"))
(h1 (@ (class "main__title")) ,(post-title post))
(div (@ (class "post__metadata"))
(div (@ (class "post__metadata-items"))
(span (@ (class "post__subtitle"))
,(date->string* (post-date post)))
(ul (@ (class "tags"))
,@(map (lambda (tag)
`(li (@ (class "tag"))
(a (@ (href
,(string-append "/feeds/tags/"
tag ".xml"))
(class "tag__link"))
,tag)))
(post-ref post 'tags)))))
(div (@ (class "post__container")) ,(post-sxml post)))))
(define (project-template project)
`((div (@ (class "post project"))
(h1 (@ (class "main__title")) ,(post-title project))
(div (@ (class "post__metadata"))
(div (@ (class "post__metadata-items"))
,(anchor "GitHub"
(format #f "https://github.com/~a/~a"
%username (post-title project))
#:external? #t
#:extra-classes "project__link")
,(anchor "Cgit"
(format #f "https://git.~a/~a"
%domain (post-title project))
#:external? #t
#:extra-classes "project__link")
,(post-ref project 'license))
(div (@ (class "post__metadata-items"))
(h4 (@ (class "post__subtitle"))
,(post-ref project 'synopsis))
(ul (@ (class "tags"))
,@(map (lambda (tag)
`(li (@ (class "tag")) ,tag))
(post-ref project 'tags)))))
(div (@ (class "project__container"))
,@(post-sxml project)))))
(define (blog-template site title posts prefix)
`((div (@ (class "blog"))
(div (@ (class "main__title"))
(h1 (@ (class "blog__title")) ,title)
(button (@ (class "button button--type-border"))
,(anchor "Feed" "/feed.xml")))
(div (@ (class "blog-entries"))
,@(blog-entries site (posts/reverse-chronological posts))))))
(define (portfolio-template site title projects prefix)
`((div (@ (class "portfolio"))
(div (@ (class "main__title"))
(h1 (@ (class "portfolio__title")) ,title))
(div (@ (class "portfolio-entries"))
,@(portfolio-entries site projects)))))
(define %blog-collections
`(("Blog" ,(format #f "~a/index.html" %blog-prefix) ,posts/reverse-chronological)))
(define %portfolio-collections
`(("Projects" ,(format #f "~a/index.html" %portfolio-prefix) ,identity)))
(define %blog-theme
(theme #:name %username
#:layout base-layout
#:post-template post-template
#:collection-template blog-template))
(define %portfolio-theme
(theme #:name %username
#:layout base-layout
#:post-template project-template
#:collection-template portfolio-template))
;;
;; Pages
;;
(define index-page
(lambda (site posts)
(list
(serialized-artifact
"index.html"
(with-layout
%blog-theme site "Home"
`((div
(@ (class "hero"))
(h1 (@ (class "hero__title"))
,(format #f "Hi, I'm ~a"
(string-join
(drop-right (string-split %fullname #\space) 1))))
(p "Software developer with experience in project settings across
different industries. Enthusiastic about building robust solutions following
correct practices. Particularly interested in functional programming."))
(div (@ (class "blog blog--type-preview"))
(h2 (@ (class "blog__title")) "Latest Posts"
(button (@ (class "button button--type-border"))
,(anchor "See all" "/blog")))
(div (@ (class "blog-entries"))
,(blog-entries site
(posts/reverse-chronological
(remove (lambda (post)
(post-ref post 'projects))
posts)))))
(div (@ (class "portfolio portfolio--type-preview"))
(h2 (@ (class "portfolio__title")) "Projects"
(button (@ (class "button button--type-border"))
,(anchor "See all" "/projects")))
(div (@ (class "portfolio-entries"))
,@(portfolio-entries site
(take (filter (lambda (post)
(post-ref post 'projects))
posts)
6))))))
sxml->html))))
(define (contact-entry title text)
`(div (@ (class "descriptions__wrapper"))
(dt (@ (class "descriptions__title")) ,title)
(dd (@ (class "descriptions__text")) ,text)))
(define contact-page
(static-page
"Contact"
"/contact.html"
`((h1 (@ (class "main__title")) "Contact me")
(dl (@ (class "list"))
,(contact-entry
'(span "Email")
'(span (code "mail") " at " (code "$DOMAIN")))
,(contact-entry
'(span "PGP")
(anchor '(code "4956 DAC8 B077 15EA 9F14 E13A EF1F 69BF 5F23 F458")
"/assets/pubkey.asc"
#:external? #t))))))
(define not-found-page
(static-page
"404 Not found"
"/404.html"
`((div (@ (class "not-found"))
(h1 "404")
(h1 "Not Found")))))
(define (portfolio)
(define portfolio-blog
(blog #:prefix %portfolio-prefix
#:theme %portfolio-theme
#:collections %portfolio-collections))
(lambda (site posts)
(portfolio-blog site
(filter (lambda (post) (post-ref post 'projects)) posts))))
(define (make-builder-with-blog-posts builder)
(lambda (site posts)
(builder site (remove (lambda (post) (post-ref post 'projects)) posts))))
(site #:title %fullname
#:domain %domain
#:default-metadata
`((author . ,%fullname)
(email . ,%email))
#:readers (list (make-dir-tagging-reader html-reader)
(make-dir-tagging-reader org-mode-reader)
(make-dir-tagging-reader commonmark-reader))
#:builders (list index-page
(portfolio)
(make-builder-with-blog-posts
(blog #:prefix %blog-prefix
#:theme %blog-theme
#:collections %blog-collections))
contact-page
not-found-page
(make-builder-with-blog-posts (atom-feed))
(make-builder-with-blog-posts (atom-feeds-by-tag))
(static-directory "assets")))