summaryrefslogtreecommitdiff
path: root/skribe-utils.scm
blob: 8788c5211c378ba1b63f905934446119b9de4a89 (about) (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
(define-module (skribe-utils)
  #:use-module (ice-9 match)  ; match-lambda
  #:use-module (srfi srfi-1)  ; list stuff
  #:export (email
            ~
            ---
            table
            lyrics
            ref
            figure
            wide-img))

(define (email address)
  "Obfuscate a given email ADDRESS."
  `(span (@ (class "obfuscated"))
         ,(string-map (lambda (c) (integer->char (+ 1 (char->integer c))))
                      address)))

(define (~)
  "Non-breaking space."
  (string #\240))

(define (---)
  "Em dash." "—")

(define* (table #:key (align '()) headers rows)
  "Build HTML tables more easily."
  (let ((alignment (append align
                           (make-list (- (length headers)
                                         (length align))
                                      "left"))))
    (define (make-row fields)
      `(tr ,(map (match-lambda
                  ((field alignment)
                   `(td (@ (align ,alignment)) ,field)))
                 (zip fields alignment))))
    (define (make-header fields)
      `(tr (@ (class "header"))
           ,(map (match-lambda
                  ((field alignment)
                   `(th (@ (align ,alignment)) ,field)))
                 (zip fields alignment))))
    `(table
      (thead ,(make-header headers))
      (tbody ,(map make-row rows)))))

(define (lyrics . contents)
  `(pre (@ (class "lyrics")) ,contents))

(define (ref url text)
  `(a (@ (href ,url)) ,text))

(define (figure file caption)
  `(div (@ (class "figure"))
        (img (@ (src ,(if (string-prefix? "/" file)
                          file
                          (string-append "/images/posts/" file)))
                (alt ,caption)))
        (p (@ (class "caption")) ,caption)))

(define (wide-img file alt)
  `(img (@ (class "full stretch")
           (src ,(if (string-prefix? "/" file)
                     file
                     (string-append "/images/posts/" file)))
           (alt ,alt))))