~aasg/haunted-blog

ref: 3879a21d2b94755cd14850824e1cd16e9591fff7 haunted-blog/haunt.scm -rw-r--r-- 7.6 KiB
3879a21d — Aluísio Augusto Silva Gonçalves css: Sort out the site's color scheme 1 year, 5 months ago
                                                                                
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
; vim: set fdm=marker fmr=;+,;- :

;---------
;+ Imports

(use-modules (haunt asset)
             (haunt builder blog)
             (haunt builder atom)
             (haunt builder assets)
             (haunt html)
             (haunt reader commonmark)
             (haunt page)
             (haunt post)
             (haunt site)
             (ice-9 match)
             (ice-9 textual-ports)
             (srfi srfi-1)
             (srfi srfi-19)
             (srfi srfi-26)
             (sxml match)
             (sxml simple)
             (sxml transform))

;-----------
;+ Constants

(define %copyright-notice "© 2020 Aluísio Augusto Silva Gonçalves")

;----------------
;+ I/O procedures

(define (read-asset path)
  (call-with-input-file path get-string-all))

(define (output-directory)
  (or (getenv "HAUNT_DESTDIR") "site"))

;----------------
;+ Markup helpers

(define (prefix-sxml prefix tree)
  (if tree (list prefix tree) `()))

(define (humanize-url url)
  ; TODO: look at sindresorhus' humanize-url and normalize-url
  ; if we ever actually use this
  url)

(define (link-as name uri)
  `(a (@ (href ,uri)) ,name))

(define (embedded-icon name)
  (let ((icon-path (string-append "assets/icons/" (symbol->string name) ".svg")))
    `(raw ,(read-asset icon-path))))

(define (profile-link icon-name uri)
  `(a (@ (rel "me")
         (href ,uri))
      ,(embedded-icon icon-name)))

(define (hcard name url)
  (cond
      ((and name url)
       `(a (@ (class "p-author h-card")
              (href ,url))
           ,name))
      (name
        `(span (@ (class "p-author h-card")) ,name))
      (else #f)))

;-------
;+ Theme

(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 (aasg-layout site title body)
  `((doctype "html")
    (head
      (meta (@ (charset "utf-8")))
      (meta (@ (name "viewport")
               (content "width=device-width, initial-scale=1")))
      (title ,(string-append title " — " (site-title site)))
      (base (@ (href ".")))
      (link (@ (rel "stylesheet")
               (href "css/a11y.css")))
      (link (@ (rel "stylesheet")
               (href "css/classless.css")))
      (link (@ (rel "stylesheet")
               (href "css/site.css"))))
    (body
      (header
        (nav (@ (class "profile-links"))
             (ul
               (li ,(link-as (embedded-icon 'signature) "index.html"))
               (li ,(profile-link 'email "mailto:aluisio@aasg.name"))
               (li ,(profile-link 'matrix "https://matrix.to/#/@aasg:aasg.name"))
               (li ,(profile-link 'github "https://github.com/AluisioASG"))
               (li ,(profile-link 'gitlab "https://gitlab.com/AluisioASG"))
               (li ,(profile-link 'linkedin "https://www.linkedin.com/in/aasg/")))))
      ,body
      (footer (p
                (a (@ (rel "license")
                      (href "https://creativecommons.org/licenses/by-sa/4.0/")
                      (title "Creative Commons Attribution-ShareAlike 4.0 International")
                      (aria-label "Creative Commons Attribution-ShareAlike 4.0 International"))
                   "\U01F16D\U01F16F\U01F10E")
                " Aluísio Augusto Silva Gonçalves. "
                ,(about-site-page-link `("Built with, powered by, licensed under, "
                                         (i "et cetera, et cetera, et cetera")
                                         ".")))))))

(define (author-hcard post)
  (let* ((metadata (cute assq-ref (post-metadata post) <>))
         (author-name (metadata 'author))
         (author-url (metadata 'author-profile)))
    (hcard author-name author-url)))

(define (cite-if-reply post)
  (let* ((metadata (cute assq-ref (post-metadata post) <>))
         (irt-url (metadata 'in-reply-to))
         (irt-desc (metadata 'irt-description))
         (irt-title (metadata 'irt-title))
         (irt-author-name (metadata 'irt-author))
         (irt-author-url (metadata 'irt-author-profile)))
    (if (not irt-url) #f
        `(span (@ (class "u-in-reply-to h-cite"))
               (cite
                 (a (@ (class ,(if irt-title "u-url p-name" "u-url"))
                       (href ,irt-url))
                    ,(or irt-title irt-desc (humanize-url irt-url)))
                 ,(prefix-sxml " by " (hcard irt-author-name irt-author-url)))))))

(define (aasg-post-template post)
  `(article (@ (class "h-entry"))
            (small (@ (class "post-info"))
              "Published on "
              (time (@ (class "dt-published")) ,(date->string (post-date post) "~1"))
              " by "
              ,(author-hcard post)
              ,(prefix-sxml " in reply to " (cite-if-reply post)))
            (h1 (@ (class "p-name")) ,(post-ref post 'title))
            (div (@ (class "e-content")) ,(post-sxml post))))

(define (aasg-collection-template site title posts prefix)
  (define (post-uri post)
    (string-append (or prefix "") (site-post-slug site post) ".html"))
  `((h1, "Hi!")
    (h1 ,title)
    ,(map (lambda (post)
            `(article
               (h2 ,(link-as (post-ref post 'title) (post-uri post)))
               (time ,(date->string (post-date post) "~1"))
               ,(first-paragraph post)
               ,(link-as "continue…" (post-uri post))))
          posts)))

(define aasg-theme
  (theme #:name "aasg"
         #:layout aasg-layout
         #:post-template aasg-post-template
         #:collection-template aasg-collection-template))

;-------
;+ Pages

(define (static-page file-name title body)
  (lambda (site posts)
    (make-page file-name
               (with-layout aasg-theme site title body)
               sxml->html)))

(define (about-site-page-link text)
  (link-as text "about-site.html"))
(define about-site-page
  (static-page
    "about-site.html"
    "About this site"
    `((h1 "About this site")
      (p "As the site title says, this is aasg's highly experimental blog, currently built with the "
         ,(link-as "Haunt" "https://dthompson.us/projects/haunt.html")
         " static site generator and styled with "
         ,(link-as "Classless.css" "https://classless.de")
         " using the default "
         ,(link-as "base16" "http://chriskempson.com/projects/base16/")
         " color scheme.")
      (section (@ (id "license"))
               (p "Except where otherwise noted, this site is "
                  ,%copyright-notice
                  ", and released under a "
                  ,(link-as "Creative Commons Attribution-ShareAlike 4.0 International" "https://creativecommons.org/licenses/by-sa/4.0/")
                  " license. Exceptionally, fragments of software source code are instead released under the "
                  ,(link-as "CC0 1.0 Universal Public Domain Dedication" "https://creativecommons.org/publicdomain/zero/1.0/")
                  ".")))))

;-----------------
;+ Site definition

(define (aasg-post-slug post)
  (or
    (assq-ref (post-metadata post) 'slug)
    (basename (post-file-name post) ".md")))

(site #:title "aasg's most experimental weblog"
      #:domain "aasg.name"
      #:default-metadata
      '((author . "Aluísio Augusto Silva Gonçalves"))
      #:readers (list commonmark-reader)
      #:builders (list (blog #:theme aasg-theme)
                       (atom-feed)
                       about-site-page
                       (static-directory "static/css" "css")
                       (static-directory "static/fonts" "fonts"))
      #:build-directory (output-directory)
      #:make-slug aasg-post-slug)