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
|
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
;;; Copyright © 2023-2024 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
;;;
;;; This file is based on haunt/builder/blog.scm,
;;; haunt/reader/commonmark.scm and tests/post.scm and from Haunt
;;; 2.6.0.
;;;
;;; This file 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.
;;;
;;; Haunt 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 Haunt. If not, see <http://www.gnu.org/licenses/>.
(define-module (website builders replicant-blog)
#:use-module (commonmark)
#:use-module (haunt artifact)
#:use-module (haunt builder assets)
#:use-module (haunt html)
#:use-module (haunt post)
#:use-module (haunt site)
#:use-module (haunt utils)
#:use-module (ice-9 match)
#:use-module (ice-9 rdelim)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-19)
#:export (theme-collection-template)
#:export (make-theme)
#:export (render-collection)
#:export (render-post)
#:export (replicant-blog-website)
#:export (replicant-default-post-template)
#:export (replicant-layout)
#:export (replicant-theme)
#:export (theme)
#:export (theme-layout)
#:export (theme-name)
#:export (theme-post-template)
#:export (theme?))
(fluid-set! %default-port-encoding "UTF-8")
(define-record-type <theme>
(make-theme name layout post-template collection-template)
theme?
(name theme-name)
(layout theme-layout)
(post-template theme-post-template)
(collection-template theme-collection-template))
(define (replicant-layout site title body)
`((doctype "html")
(head
(meta (@ (charset "utf-8")))
(link
(@ (rel "stylesheet")
(href "static/twentyeleven-style-20231107.css")))
(title ,(string-append title " - " (site-title site))))
(body
(header
(img (@ (id "banner")
(src "static/replicant_banner_white.png")
(alt "Replicant banner")))
(nav
(@ (id "access"))
(ul
(li (a (@ (href "https://www.replicant.us"))
"Home"))
(li (a (@ (href "/")
(id "blog-link")
)
"Blog"))
(li (a (@ (href "https://redmine.replicant.us/projects/replicant/wiki"))
"Wiki"))
(li (a (@ (href "https://redmine.replicant.us/projects/replicant/issues"))
"Tracker"))
(li (a (@ (href "https://redmine.replicant.us/projects/replicant/boards"))
"Forums"))
(li (a (@ (href "/search.html"))
"Blog: Search")))))
,body)))
(define (replicant-default-post-template post)
`((h1 (@ (id "title")) ,(post-ref post 'title))
;; Metadata
(p (string-append
"Posted"
,(if
(post-ref post 'authors)
(string-append " by " (post-ref post 'authors))
"")
,(if
(post-ref post 'date)
(string-append
" on the "
(date->string (post-ref post 'date) "~d ~B ~Y at ~kh~M"))
"")
,(if (post-ref post 'licenses)
(string-append
" under the "
(post-ref post 'licenses) " license(s)")
"")
"."))
(div (@ (id "post-content")) ,(post-sxml post))))
(define (sort-posts-by-most-recent-first a b)
(time>?
(date->time-utc (post-ref a 'date))
(date->time-utc (post-ref b 'date))))
(define (replicant-default-collection-template site title posts prefix)
(define (post-uri post)
(string-append (or prefix "") "/"
(site-post-slug site post) ".html"))
`((h3 ,title)
(ul
,@(map (lambda (post)
`(li
(a (@ (href ,(post-uri post)))
,(post-ref post 'title))))
(sort posts sort-posts-by-most-recent-first)))))
(define* (theme #:key
(name "Replicant")
(layout replicant-layout)
(post-template replicant-default-post-template)
(collection-template replicant-default-collection-template))
(make-theme name layout post-template collection-template))
(define (with-layout theme site title body)
((theme-layout theme) site title body))
(define (render-post theme site post)
(let ((title (post-ref post 'title))
(body ((theme-post-template theme) post)))
(with-layout theme site title body)))
(define (render-collection theme site title posts prefix)
(let ((body ((theme-collection-template theme) site title posts prefix)))
(with-layout theme site title body)))
(define (date->string* date)
"Convert DATE to human readable string."
(date->string date "~a ~d ~B ~Y"))
(define replicant-theme
(theme #:name "Replicant"
#:layout replicant-layout
#:post-template replicant-default-post-template
#:collection-template replicant-default-collection-template))
(define* (replicant-blog-website #:key (theme replicant-theme) prefix
(collections
`(("" "index.html" ,posts/reverse-chronological))))
"Return a procedure that transforms a list of posts into pages
decorated by THEME, whose URLs start with PREFIX."
(define (make-file-name base-name)
(if prefix
(string-append prefix "/" base-name)
base-name))
(lambda (site posts)
(define (post->page post)
(let ((base-name (string-append (site-post-slug site post)
".html")))
(serialized-artifact (make-file-name base-name)
(render-post theme site post)
sxml->html)))
(define collection->page
(match-lambda
((title file-name filter)
(serialized-artifact (make-file-name file-name)
(render-collection theme site title (filter posts) prefix)
sxml->html))))
(append (map post->page posts)
(map collection->page collections))))
|