summaryrefslogtreecommitdiff
path: root/builder/base.scm
blob: 3e83ac65c7bd00a52fb7f9c0f728f1a208fdbc59 (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
(define-module (builder base)
  #:use-module (haunt site)
  #:use-module (builder components)
  #:use-module (json)
  #:export (base-template
            contained-template
            page-template))

(define stylesheets
  (list "https://fonts.bunny.net/css?family=alegreya:400,400i,800,800i"
        "/static/normalize.css"
        "/static/reset.css"
        "/static/main.css"))

(define open-graph
  '(("og:title" "Eltrac")
    ("og:url" "https://eltr.ac")
    ("og:image" "/static/avatar.jpg")
    ("og:type" "profile")
    ("profile:username" "Eltrac")))

(define (base-template site page-title . content)
  (let ((title (if page-title
                   (string-append page-title " · " (site-title site))
                   (site-title site))))
    `((doctype "html")
      (html (@ (lang "en"))
        (head
         (meta (@ (charset "utf-8")))
         (meta (@ (content "width=device-width,initial-scale=1")
                  (name "viewport")))
         (link (@ (rel "icon") (href "/static/favicon.ico")))
         (link (@ (rel "preconnect")
                  (href "https://fonts.bunny.net")))
         ;; Open Graph
         ,@(map (lambda (item) 
                  `(meta (@ (name ,(car item)) (value ,(list-ref (cdr item) 0))))) 
                open-graph)
         ;; JSON-LD
         (script (@ (type "application/ld+json"))
           ,(scm->json-string
              '(("@context" . "https://schema.org")
                ("@type" . "Person")
                ("name" . "Eltrac")
                ("url" . "https://eltr.ac")
                ("image" . "https://eltr.ac/static/avatar.jpg")
                ("description" . "I write software, fictions and non-fictions.")
                ("email" . "mailto:hi@eltr.ac")
                ("sameAs" . #("https://geedea.pro/"
                              "https://geedea.pro/en/"
                              "https://codeberg.org/eltrac")))))
         ;; stylesheet
         ,@(map (lambda (uri) 
                  `(link (@ (rel "stylesheet") (href ,uri)))) 
                stylesheets)
         (title ,title))
        (body ,@content)))))

(define (container content)
  `(div (@ (class "container"))
        ,@content))

(define (contained-template site . content)
  (base-template site #f (container content)))

(define (page-template site metadata body)
  (base-template site
    (assq-ref metadata 'title)
    (container (list `(main (@ (class "page prose")) 
                           ,body)
                     `(footer (@ (style "margin: 2rem 0"))
                        ,(link "/" "← Back to homepage"))))))