-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.scm
More file actions
70 lines (61 loc) · 2.42 KB
/
Copy pathutils.scm
File metadata and controls
70 lines (61 loc) · 2.42 KB
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
(define-module (utils)
#:use-module (ice-9 rdelim)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-1)
#:use-module (haunt post)
#:export (date
stylesheet
anchor
link
centered-image
raw-snippet
post-date-time
post-tags-sxml
post-html-datetime)
#:replace (link))
(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 (link name uri)
`(a (@ (href ,uri)) ,name))
(define* (centered-image url #:optional alt)
`(img (@ (class "centered-image")
(src ,url)
,@(if alt
`((alt ,alt))
'()))))
(define (raw-snippet code)
`(pre (code ,(if (string? code) code (read-string code)))))
(define (post-tags-sxml post)
"Add an HTML div element that lists all tags used in POST's metadata."
(define (remove-last-elem l)
"Remove the last element of L."
(drop-right l 1))
(let* ((tags-li (map
(lambda (tag)
`((li (@ (class "tag")) ,tag)))
(post-tags post)))
;; We use a hard-coded comma and space in the string because the
;; alternative is to use CSS. Using CSS would be fine, but some web
;; browsers (like eww) do not support CSS whatsoever. So the tags would
;; be just one big mashing of all letters. This lets us force readability
;; in non-CSS browsers. The CSS option is commented out in the main CSS
;; file.
(commas (make-list (length tags-li) ", ")))
`(ul (@ (class "tags"))
;; FIXME With this method, we need to drop the last comma in the map's
;; output list!
,@(remove-last-elem (append-map list tags-li commas)))))
(define (post-html-datetime post)
"Return a properly formatted HTML <time> element for POST's datetime that
has the full datetime in the element's tag and a human-readable date in the
element's body."
`(time (@ (datetime ,(date->string (post-date post) "~4")))
,(date->string (post-date post)
"~B ~d, ~Y")))