summaryrefslogtreecommitdiff
path: root/src/theme.scm
blob: 7ce23f345c003aa415dbcf8a4dc1403ebabb1234 (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
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
(define-module (src theme)
  #:use-module (srfi srfi-19)
  #:use-module (haunt post)
  #:use-module (haunt site)
  #:use-module (haunt builder blog)
  #:use-module (src urls)
  #:use-module (src date-utils)
  #:export (weekly-news-theme))

(define (weekly-news-layout site title body)
  `((doctype "html")

    (html
     (@ (lang "en"))

     (head
      ,(if (null? title)
           `(title "Guix Weekly News")
           `(title ,(string-append title " — Guix Weekly News")))
      (meta (@ (charset "UTF-8")))
      (meta (@ (name "viewport")
               (content "width=device-width, initial-scale=1.0")))
      ;; Base CSS.
      (link (@ (rel "stylesheet") (href "/static/css/base.css")))
      ;; Feeds.
      (link (@ (type "application/atom+xml") (rel "alternate")
               (title "GNU Guix — Activity Feed")
               (href "feeds/blog.atom")))
      (link (@ (rel "icon") (type "image/png")
               (href "/static/img/icon.png")))
      (link (@ (rel "icon") (type "image/svg+xml") (sizes "any")
               (href "/static/img/icon.svg"))))

     (body
      (header
       (a (@ (href "/"))
          (h2
           (@ (style "color: white; margin: 0.4em; font-size: 2em;"))
           (img (@ (style "height: 1.1em;")
                   (src "/static/img/guix-logo.png")))
           "Guix Weekly News")))
      (main
       (article
        (@ (class "page centered-block limit-width"))
        ,body))
      (footer
       "Made with " (span (@ (class "metta")) "♥")
       " by humans and powered by "
       (a (@ (class "link-yellow") (href ,(gnu-url "software/guile/")))
          "GNU Guile") ".  "
          (a
           (@ (class "link-yellow")
              (href "https://git.cbaines.net/guix/weekly-news/"))
           "Source code")
          " under the "
          (a
           (@ (class "link-yellow")
              (href ,(gnu-url "licenses/agpl-3.0.html")))
           "GNU AGPL") ".")))))

(define (is-year-and-week-a-draft? year week)
  (time>? (date->time-utc
           (lookup-end-date-for-week year week))
          (current-time)))

(define (weekly-news-post-template post)
  (let ((year (post-ref post 'year))
        (week (post-ref post 'week)))
    `((div
       ,@(or (and=>
              (previous-week-with-year year week)
              (lambda (previous-week-and-year)
                `((a (@ (href ,(apply weekly-news-post-url
                                      previous-week-and-year)))
                     (span (@ (id "left-nav"))
                           "Previous week")))))
             '())
       (h1 (@ (id "center"))
           ,(post-ref post 'title))
       ,@(or (and=>
              (and (and=> (next-week-with-year year week)
                          (lambda (next-week-and-year)
                            (not (apply is-year-and-week-a-draft?
                                        next-week-and-year))))
                   (next-week-with-year year week))
              (lambda (next-week-and-year)
                `((a (@ (href ,(apply weekly-news-post-url
                                      next-week-and-year)))
                     (span (@ (id "right-nav"))
                           "Next week")))))
             '()))
      (div
       (@ (style "text-align: center;"))
       ,(date->string (post-ref post 'start-date) "~1")
       " to "
       ,(date->string (post-ref post 'end-date) "~1"))
      (br)
      ,(post-sxml post))))

(define (weekly-news-collection-template site title posts prefix)
  (define (post-uri post)
    (string-append (or prefix "") "/"
                   (site-post-slug site post) ".html"))

  (define (date->string* date)
    (date->string date "~a ~d ~b"))

  `((ul
     (@ (id "post-list"))
     ,@(map (lambda (post)
              (let ((draft
                     (time>? (date->time-utc
                              (post-ref post 'end-date))
                             (current-time))))
                `(li
                  (@ (class ,(if draft "draft-post" "")))
                  ,(if draft
                       `((time
                          "Week " ,(post-ref post 'week)
                          (div
                           (@ (style "font-size: small;"))
                           "Beginning "
                           ,(date->string*
                             (post-ref post 'start-date))))
                         ,(string-append
                           "Will be published on "
                           (date->string (move-date-by-days
                                          (post-ref post 'start-date)
                                          7)
                                         "~A (~1)")))
                       `(a (@ (href ,(post-uri post)))
                           (time
                            "Week " ,(post-ref post 'week)
                            (div
                             (@ (style "font-size: small;"))
                             "Beginning "
                             ,(date->string*
                               (post-ref post 'start-date))))
                           ,(post-ref post 'synopsis))))))
            posts)
     ,@(if (string=? title "Recent posts")
           '((li
              (a (@ (style "margin-bottom: 1em;")
                    (href "/all.html"))
                 "All posts")))
           '()))))

(define weekly-news-theme
  (theme #:name "Weekly news"
         #:layout weekly-news-layout
         #:post-template weekly-news-post-template
         #:collection-template weekly-news-collection-template))