aboutsummaryrefslogtreecommitdiff
path: root/haunt.scm
blob: 225fb5f32214ab4352ae2a2160ac23386063208f (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;;; TojoQK's website --- TojoQK's personal website
;;; Copyright © 2020, 2021 Masaya Tojo <masaya@tojo.tokyo>
;;;
;;; This file is part of TojoQK's website
;;;
;;; TojoQK's website is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; TojoQK's website is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with TojoQK's website.  If not, see <https://www.gnu.org/licenses/>.

(use-modules (haunt asset)
             (haunt site)
             (haunt builder blog)
             (haunt builder atom)
             (haunt builder assets)
             (haunt reader)
             (www-tojo-tokyo reader org)
             (srfi srfi-19)
             (haunt post)
             (sxml simple))

(define site-name "TojoQK")

(define (date->string/tojoqk date)
  (date->string date "~Y年~m月~d日 ~H時~M分"))

(define (post-slug/tojoqk post)
  (post-ref post 'id))

(define (updated->date-or-false updated)
  (cond
   ((date? updated) updated)
   ((string? updated) (string->date* updated))
   (else updated)))

(define* (post-url post #:optional prefix)
  (string-append "/"
                 (if prefix
                     (string-append prefix "/")
                     "")
                 (post-slug/tojoqk post)
                 ".html"))

(define (theme/tojoqk)
  (theme
   #:layout
   (lambda (site title obj)
     (let ((og (car obj))
           (sxml (cdr obj)))
       `((doctype "html")
         (head
          (@ (lang "ja")
             (prefix "og: http://ogp.me/ns#"))
          (meta (@ (charset "utf-8")))
          (link (@ (rel "stylesheet") (href "/static/css/blog.css")))
          ,@(map
             (lambda (pxp)
               `(link (@ (rel "icon")
                         (type "image/png")
                         (href ,(string-append "/static/image/QK-" pxp ".png"))
                         (sizes pxp))))
             (list "16x16" "32x32" "96x96"))
          ,@(map
             (lambda (pxp)
               `(link (@ (rel "apple-touch-icon")
                         (href ,(string-append "/static/image/QK-" pxp ".png"))
                         (sizes ,pxp))))
             (list "57x57" "60x60" "72x72" "76x76" "114x114" "152x152" "180x180"))
          (meta (@ (property "og:title") (content ,(assoc-ref og 'title))))
          (meta (@ (property "og:type") (content ,(assoc-ref og 'type))))
          (meta (@ (property "og:url") (content ,(assoc-ref og 'url))))
          ,@(cond
             ((assoc-ref og 'description)
              => (lambda (description)
                   `((meta (@ (name "description") (content ,description)))
                     (meta (@ (property "og:description") (content ,description))))))
             (else '()))
          (meta (@ (property "og:site_name") (content ,site-name)))
          (meta (@ (property "og:image")
                   (content
                    ,(string-append "https://"
                                    (site-domain site)
                                    (or (assoc-ref og 'image) "/static/image/QK.png")))))
          (meta (@ (name "viewport")
                   (content "initial-scale=1.0")
                   (width "device-width")))
          (title
           ,(if (string=? title site-name)
                site-name
                (string-append title " -- " site-name))))
         (body
          (div (@ (class "world"))
               (nav (@ (class "nav-bar"))
                    (ul (@ (class "nav-list"))
                        (li (@ (class "nav-logo"))
                            (a (@ (href "/")) "TojoQK"))
                        (li (@ (class "nav-item"))
                            (a (@ (href "/about-me.html")) "About me"))
                        (li (@ (class "nav-item"))
                            (a (@ (href "/contact.html")) "Contact"))))
               (article (@ (class "main"))
                        ,sxml))))))
   #:collection-template
   (lambda (site title posts prefix)
     (cons
      `((title . ,title)
        (type . "website")
        (description . "TojoQKの日記")
        (url . "/"))
      `((p (a (@ (rel "me")
                 (href "https://mastodon.tojo.tokyo/@tojoqk"))
              "Mastodon(@tojoqk@mastodon.tojo.tokyo)")
           " でも活動しています")
        (h1 "最近の投稿")
        (ul (@ (class "post-list"))
            ,@(map (lambda (post)
                     (let ((url (post-url post)))
                       `(li (div (@ (class "post-list-item"))
                                 (a (@ (href ,url))
                                    ,(post-ref post 'title))
                                 (div (@ (class "post-list-date"))
                                      ,(date->string/tojoqk
                                        (post-date post)))))))
                   posts)))))
   #:post-template
   (lambda (post)
     (cons
      `((title . ,(post-ref post 'title))
        (type . "article")
        (url . ,(post-url post))
        (description . ,(post-ref post 'description)))
      `((div (h1 (@ (class "post-title"))
                 (a (@ (href "")) ,(post-ref post 'title)))
             (div (@ (class "post-date"))
                  "投稿日: ",(date->string/tojoqk (post-date post)))
             ,@(cond
                ((updated->date-or-false (post-ref post 'updated))
                 => (lambda (updated)
                      `((div (@ (class "post-date"))
                             "更新日: " ,(date->string/tojoqk updated)
                             " ("
                             (a (@ (href ,(string-append
                                           "https://git.tojo.tokyo/"
                                           "www-tojo-tokyo.git/log/"
                                           (post-file-name post))))
                                "更新履歴")
                             ")"))))
                (else '())))
        (div ,(post-sxml post))
        (ul (@ (class "post-end"))
            (li (a (@ (href "/")) "投稿の一覧"))
            (li (a (@ (href ,(string-append "https://git.tojo.tokyo/www-tojo-tokyo.git/tree/"
                                            (post-file-name post))))
                   "このページのソースコード"))
            (li (a (@ (href "feed.xml")) "RSSフィードを購読する"))))))))

(define (blog/tojoqk)
  (blog #:theme (theme/tojoqk)
        #:collections (list (list site-name "index.html" posts/reverse-chronological))))

(site #:title site-name
      #:domain "www.tojo.tokyo"
      #:default-metadata
      '((author . "Masaya Tojo")
        (email  . "masaya@tojo.tokyo"))
      #:readers (list sxml-reader org-reader)
      #:builders (list (blog/tojoqk)
                       (atom-feed)
                       (static-directory "static"))
      #:make-slug post-slug/tojoqk)