summaryrefslogtreecommitdiff
path: root/templates/_defs.scm
blob: ed145b4cacd579a8c768095ff822ae32acf6e4c3 (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
; Global to the file, use (set! lang "lang") to configure in languages
(define lang "en")

; UTILS -----------------------------------------------------------------------
(define (anchored-h level title id)
  `(,(string->symbol (string-append "h" (number->string level)))
     (@ (id ,id))
     ,title
     (a (@ (href ,(string-append "#" id)) (class "anchor")) " ¶" )))


(define (absurl-to-lang url)
  (string-append "/" lang url))

(define (header-link lr text title link active)
  `(a (@ (class ,(string-append (if active "active " " ")
                                "navbar-link link-" lr))
         (href ,link)
         (title ,title))
      ,text))

(define (style href)
  "Make <link> tags to add CSS"
  `(link (@ (rel "stylesheet")
            (href ,href))))

(define (md markdown-text)
  `(@raw ,(md-to-html markdown-text)))

(define (logo-title) `(h1 (@raw ,(file->string "templates/_logo.svg"))))

; BASE ------------------------------------------------------------------------
(define (base title body)
  `(html
    (@ (lang ,lang))
    (head
      (meta (@ (charset "utf-8")))
      (meta (@ (name "viewport")
               (content "width=device-width, initial-scale=1")))
      ,(style "/static/css/normalize.css")
      ,(style "/static/css/style.css")
      ,(style "/static/css/fonts.css")
      ,(style "/static/css/extra-style.css")
      ,(style "/static/css/publishing.css")
      (title ,title))
    (body ,body)))


; HEADER-----------------------------------------------------------------------
(define (nav-link l)
  (header-link "left"
               (cdr (assq 'name l))
               (cdr (assq 'title l))
               (cdr (assq 'absurl l))
               (or (assq 'active l) #f)))

(define (lang-link l)
  (header-link "right"
               (cdr (assq 'name l))
               (cdr (assq 'title l))
               (cdr (assq 'absurl l))
               (or (assq 'active l) #f)))

(define (header links langs)
  `(header
     (@ (class mainheader))
     (div (@ (class container))
          (nav (@ (class navbar))
               (label (@ (id hamburger-label)
                         (for "hamburger")
                         (class "navbar-link link-left")) (@raw "&#9776;"))
               (input (@ (id "hamburger") (type checkbox)))

               (div (@ (class navbar-contents))
                    (div (@ (class navbar-left))
                         ,(map nav-link links))

                    (div (@ (class "navbar-right"))
                         ,(map lang-link langs)))))))


(define (book thickness cover-url extra-classes)
  `(div (@ (class "book-container")
           (tabindex "0"))
        (div (@ (class ,(string-join (append '("book") extra-classes) " "))
                (style ,(string-append
                         "--book-cover: url(" cover-url ");"
                         "--book-thickness: " thickness ";")))
             (div (@ (class "_side")))
             (div (@ (class "_side")))
             (div (@ (class "_side")))
             (div (@ (class "_side")))
             (div (@ (class "_side")))
             (div (@ (class "_side"))))))

(define (link-with-title title url)
  `(a (@ (title ,title)
         (href ,url))
      ,title))