summaryrefslogtreecommitdiffstats
path: root/haunt.scm
blob: 1b0bd04c41349fe3abbe09516b54a8a85ed598dc (plain)
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
;;; The GNU Assembly Web Site
;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This program is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

(use-modules (haunt asset)
             (haunt site)
             (haunt page)
             (haunt html)
             (haunt post)
             (haunt builder assets)
             (haunt builder blog)
             (haunt builder atom)
             (haunt reader)
             (haunt reader commonmark)
             (srfi srfi-19)                       ;dates
             (srfi srfi-26)                       ;cut
             (srfi srfi-71)                       ;multiple-value let
             (ice-9 match))

(define %cwd
  (and=> (assq-ref (current-source-location) 'filename)
         dirname))

(define (base-url . location)
  (string-concatenate (cons "" location)))

(define (image-url location)
  (base-url "/static/images" location))

(define (css-url location)
  (base-url "/static/css" location))

(define* (base-layout body #:key (title "") (meta '())
                      (posts '()) site)
  (define (menubar where)
    (let ((locations
           '(("about"    "About"    "/")
             ("software" "Software" "/en/software")
             ("documents" "Documents" "/en/documents")
             ("contribute" "contribute" "/en/contribute")
             ("blog"     "Blog"     "/en/blog"))))
      `(div (@ (id "menubar")
               (class "width-control"))
            (ul
             ,@(map (match-lambda
                      ((key text path)
                       (if (and where (string=? where key))
                           `(li (@ (class "selected"))
                                (span ,text))
                           `(li (a (@ (href ,(base-url path)))
                                   ,text)))))
                    locations)
             (li (a (@ (href ,(base-url "/en/blog/feed.xml")))
                    (img (@ (alt "Atom feed")
                            (src ,(image-url "/feed.png"))))))))))
  (define front-page?
    (assoc-ref meta 'frontpage))

  `((doctype "html")
    (html (@ (lang "en"))
          (head
           (meta (@ (http-equiv "Content-Type")
                    (content "text/html; charset=utf-8")))
           (link (@ (rel "icon")
                    (type "image/x-icon")
                    (href ,(image-url "/favicon.svg"))))
           (link (@ (rel "stylesheet")
                    (href ,(css-url "/main.css"))
                    (type "text/css")
                    (media "screen")))
           (title ,title))
          (body
           ,@(if front-page?
                 '((@ (class "frontpage")))
                 '())
           (div (@ (id "header"))
                (div (@ (id "header-inner")
                        (class "width-control"))
                     (a (@ (href ,(base-url "/"))
                           (class ,(if front-page?
                                       "logo" "logo small")))
                        (img (@ (alt "The logo of the GNU Assembly")
                                (src ,(image-url (if front-page?
                                                     "/logo.svg"
                                                     "/logo-small.svg"))))))

                     ;; Add the large-font welcoming message on the
                     ;; front page.
                     ,@(if front-page?
                           `((p (@ (id "heading")
                                   (class "front-page-heading"))
                                "Welcome to the GNU Assembly!  We write "
                                (a (@ (href "/en/documents/free-software"))
                                   (emph "free software"))
                                " — software that empowers users "
                                "with individual and collective control "
                                "over their computing, from the operating "
                                "system to applications."))
                           `(,(menubar (assoc-ref meta 'menu))))))
           ,@(if front-page?
                 `(,(menubar "about"))
                 '())

           (div (@ (id "content")
                   (class "width-control"))
                (div (@ (id "content-inner"))
                     (article ,body)))

           (div (@ (id "footer-box")
                   (class "width-control"))
                (p "Unless otherwise noted, content on this site is "
                   "distributed under the "
                   (a (@ (href "https://creativecommons.org/licenses/by-sa/4.0/"))
                      "Creative Commons Attribution-ShareAlike 4.0 "
                      "International License") ".  "
                   (a (@ (href "https://wiki.gnu.tools/git/gnu-tools-website"))
                      "Source of this site") "."))))))

(define read-markdown
  (reader-proc commonmark-reader))

(define* (read-page file posts site #:optional (reader read-markdown))
  "Read the CommonMark page from FILE.  Return its final SXML
representation."
  (let ((meta body (reader (string-append %cwd "/" file))))
    (base-layout `(div (@ (class "post"))
                       (div (@ (class "post-body"))
                            ,body))
                 #:title (string-append "The GNU Assembly — "
                                        (assoc-ref meta 'title))
                 #:meta meta
                 #:posts posts
                 #:site site)))

(define (static-pages)
  "Return the list of static web pages."
  (define (markdown-page html md)
    (lambda (site posts)
      (make-page html (read-page md posts site)
                 sxml->html)))
  (define (sxml-page html sxml)
    (lambda (site posts)
      (make-page html (read-page sxml posts site (reader-proc sxml-reader))
                 sxml->html)))

  (list (markdown-page "index.html" "index.md")

        (sxml-page "/en/software/index.html"
                   "software.sxml")
        (markdown-page "/en/documents/index.html"
                       "documents.md")
        (markdown-page "/en/contribute/index.html"
                       "contribute.md")
        (markdown-page "/en/documents/index.html"
                       "documents.md")
        (markdown-page "/en/documents/roles/index.html"
                       "roles.md")
        (markdown-page "/en/documents/governance/index.html"
                       "governance.md")
        (markdown-page "/en/documents/free-software/index.html"
                       "free-software.md")
        (markdown-page "/en/documents/code-of-conduct/index.html"
                       "code-of-conduct.md")
        (markdown-page "/en/documents/social-contract/index.html"
                       "social-contract.md")))


;;;
;;; Blog.
;;;

(define (post-url post site)
  "Return the URL of POST, a Haunt blog post, for SITE."
  (let ((date (post-date post)))
    (base-url "/en/blog/"
              (number->string (date-year date))
              "/"
              (string-pad (number->string (date-month date))
                          2 #\0)

              ;; There's an implicit "/index.html" here.
              "/" (site-post-slug site post))))

(define (summarize-post post uri)
  (match (post-sxml post)
    ((('p paragraph ...) _ ...)
     `((p ,@paragraph)
       (p (a (@ (href ,uri)) "Continue reading…"))))
    (body
     body)))

(define* (post->sxml post #:key post-uri summarize?)
  "Return the SXML for POST."
  (define post-body*
    (if summarize?
        (cut summarize-post <> post-uri)
        post-sxml))

  `(div (@ (class "post"))
        (h1 (@ (class "title"))
            ,(if post-uri
                 `(a (@ (href ,post-uri))
                     ,(post-ref post 'title))
                 (post-ref post 'title)))
        (div (@ (class "post-about"))
             ,(post-ref post 'author)
             " — " ,(date->string (post-date post) "~B ~e, ~Y"))
        (hr)
        (div (@ (class "post-body"))
             ,(post-body* post))))

(define (page->sxml site title posts prefix)
  "Return the SXML for the news page of SITE, containing POSTS."
  `((div (@ (class "header"))
         (div (@ (class "post-list"))
              ,@(map (lambda (post)
                       (post->sxml post #:post-uri (post-url post site)
                                   #:summarize? #t))
                     posts)))))

(define (post->page post site)
  (make-page (string-append (post-url post site) "/index.html")
             (render-post %theme site post)
             sxml->html))

(define %theme
  ;; Theme for the rendering of the news pages.
  (theme #:name "The GNU Assembly"
         #:layout (lambda (site title body)
                    (base-layout body
                                 #:title
                                 (string-append "The GNU Assembly — "
                                                title)))
         #:post-template post->sxml
         #:collection-template page->sxml))


(site #:title "The GNU Assembly"
      #:domain "gnu.tools"
      #:default-metadata
      '((author . "The GNU Assembly")
        (email  . "assembly@lists.gnu.tools"))
      #:readers (list commonmark-reader sxml-reader)
      #:builders (append (list (static-directory "static"))
                         (static-pages)

                         ;; Blog posts.
                         (list (lambda (site posts)
                                 ;; Pages for each post.
                                 (map (cut post->page <> site) posts))

                               (lambda (site posts)
                                 ;; The main collection.
                                 (make-page
                                  "/en/blog/index.html"
                                  (render-collection
                                   %theme site
                                   "The GNU Assembly — Blog" ;title
                                   (posts/reverse-chronological posts)
                                   "/en/blog")
                                  sxml->html))

                               ;; Apparently the <link> tags of Atom entries
                               ;; must be absolute URLs, hence this
                               ;; #:blog-prefix.
                               (atom-feed #:file-name "en/blog/feed.xml"
                                          #:blog-prefix "https://gnu.tools/en/blog"))))