1 | 1 |
(load "telml.scm")
|
2 | 2 |
(load "libs.scm")
|
| 3 |
(use-modules (srfi srfi-1))
|
3 | 4 |
(use-modules (ice-9 match))
|
4 | |
|
5 | |
(define (pairs lst)
|
6 | |
(match lst
|
7 | |
((x . (y . xs)) (cons (list x y) (pairs xs)))
|
8 | |
(__ '())))
|
| 5 |
(use-modules (ice-9 ftw))
|
9 | 6 |
|
10 | 7 |
;; template-ey things and style things
|
11 | 8 |
|
|
70 | 67 |
((// (= class navlist) ul)
|
71 | 68 |
(padding-left 100px)
|
72 | 69 |
(padding-right 100px))
|
| 70 |
|
| 71 |
((// (= class archive-list) ul)
|
| 72 |
(padding-left 100px)
|
| 73 |
(padding-right 100px))
|
| 74 |
|
| 75 |
((// (= class archive-list) li)
|
| 76 |
(list-style-type none))
|
| 77 |
|
| 78 |
((= class tag-entry:before)
|
| 79 |
(content "\"#\""))
|
| 80 |
|
| 81 |
((// (= class tags) ul)
|
| 82 |
(display inline))
|
| 83 |
|
| 84 |
((= class tag:before)
|
| 85 |
(content "\"#\""))
|
| 86 |
|
| 87 |
((= class tag)
|
| 88 |
(font-style italic))
|
73 | 89 |
|
74 | 90 |
((= class sidenote)
|
75 | 91 |
(float right)
|
|
123 | 139 |
(content "application/xhtml+xml; charset=utf-8;")))
|
124 | 140 |
(style (@ (type "text/css")) ,(scss->css stylesheet))
|
125 | 141 |
(script (@ (type "text/javascript")
|
126 | |
(src "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML")))
|
| 142 |
(src "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML")) "")
|
127 | 143 |
(title ,(string-append "what happens when computer: " title)))
|
128 | 144 |
(div (@ (class "all"))
|
129 | 145 |
(div (@ (class "header"))
|
|
132 | 148 |
(div (@ (class "main")) ,content)
|
133 | 149 |
(div (@ (class "footer")) "© 2015 getty ritter"))))
|
134 | 150 |
|
| 151 |
(define (add-tags chunk tags)
|
| 152 |
(define (tag->link tag)
|
| 153 |
`(a (@ (href ,(format #f "/tag/~a/" tag))
|
| 154 |
(class tag)) ,tag))
|
| 155 |
(if (null? tags)
|
| 156 |
chunk
|
| 157 |
(append chunk
|
| 158 |
`((div (@ (class "tags"))
|
| 159 |
(ul ,(map tag->link tags)))))))
|
| 160 |
|
| 161 |
(define (get-all-posts)
|
| 162 |
(let* ((files (cddr (file-system-tree "posts")))
|
| 163 |
(files-sorted (sort files (lambda (x y)
|
| 164 |
(> (stat:mtime (cadr x))
|
| 165 |
(stat:mtime (cadr y)))))))
|
| 166 |
(map (lambda (file-entry)
|
| 167 |
(let ((filename (string-append "posts/" (car file-entry))))
|
| 168 |
(cons filename
|
| 169 |
(cons (localtime (stat:mtime (cadr file-entry)))
|
| 170 |
(car (translate-file filename))))))
|
| 171 |
files-sorted)))
|
| 172 |
|
| 173 |
(define post-file car)
|
| 174 |
(define post-time cadr)
|
| 175 |
(define post-slug caddr)
|
| 176 |
(define post-title cadddr)
|
| 177 |
(define (post-tags l)
|
| 178 |
(list-ref l 4))
|
| 179 |
|
| 180 |
(define meta-slug car)
|
| 181 |
(define meta-title cadr)
|
| 182 |
(define meta-tags caddr)
|
| 183 |
|
| 184 |
(define (date->string date)
|
| 185 |
(strftime "%Y-%m-%d" date))
|
| 186 |
|
| 187 |
(define (post->list-elem post)
|
| 188 |
(let* ((date (date->string (post-time post)))
|
| 189 |
(url (format #f "/~a/~a/" date (post-slug post)))
|
| 190 |
(title (post-title post)))
|
| 191 |
`(li ,(++ date ": ") (a (@ (href ,url)) ,title))))
|
| 192 |
|
| 193 |
(define (tag->list-elem tag)
|
| 194 |
(let ((url (format #f "/tag/~a/" tag)))
|
| 195 |
`(li (@ (class tag-entry))
|
| 196 |
(a (@ (href ,url)) ,tag))))
|
| 197 |
|
135 | 198 |
(define (archive)
|
136 | |
(let* ((metadata (read-file "site.scm")))
|
137 | |
(display (serialize-sxml (page "archive" metadata)))))
|
| 199 |
(let* ((posts (get-all-posts))
|
| 200 |
(list `(div (@ (class archive-list))
|
| 201 |
(ul
|
| 202 |
,(map post->list-elem posts)))))
|
| 203 |
(with-output-to-file "output/archive/index.html"
|
| 204 |
(lambda ()
|
| 205 |
(display (sxml->html5 (page "archive" list)))))))
|
| 206 |
|
| 207 |
(define (concat list)
|
| 208 |
(apply append list))
|
| 209 |
|
| 210 |
(define (get-tag-list posts)
|
| 211 |
(let ((c (concat (map post-tags posts))))
|
| 212 |
(delete-duplicates (sort c string<?))))
|
| 213 |
|
| 214 |
(define (get-posts-with-tag tag posts)
|
| 215 |
(filter (lambda (post) (member tag (post-tags post))) posts))
|
138 | 216 |
|
139 | 217 |
(define (tags)
|
140 | |
(let* ((metadata (read-file "site.scm")))
|
141 | |
(display (serialize-sxml (page "tags" "blah")))))
|
| 218 |
|
| 219 |
(let* ((posts (get-all-posts))
|
| 220 |
(tags (get-tag-list posts))
|
| 221 |
(tag-list `(div (@ (class archive-list))
|
| 222 |
(ul
|
| 223 |
,(map tag->list-elem tags)))))
|
| 224 |
|
| 225 |
(define (mk-tag-page tag)
|
| 226 |
(let* ((ps (get-posts-with-tag tag posts))
|
| 227 |
(list `(div (@ (class archive-list))
|
| 228 |
"pages tagged "
|
| 229 |
(span (@ (class tag)) ,tag)
|
| 230 |
":"
|
| 231 |
(ul
|
| 232 |
,(map post->list-elem ps)))))
|
| 233 |
(ensure-folder (format #f "output/tag/~a" tag))
|
| 234 |
(with-output-to-file (format #f "output/tag/~a/index.html" tag)
|
| 235 |
(lambda ()
|
| 236 |
(display (sxml->html5 (page tag list)))))))
|
| 237 |
|
| 238 |
(with-output-to-file (format #f "output/tags/index.html")
|
| 239 |
(lambda ()
|
| 240 |
(display (sxml->html5 (page "tags" tag-list)))))
|
| 241 |
|
| 242 |
(map mk-tag-page tags)))
|
| 243 |
|
| 244 |
(define (ensure-folder f)
|
| 245 |
(if (not (file-exists? f))
|
| 246 |
(mkdir f)))
|
142 | 247 |
|
143 | 248 |
;; actually load and generate the relevant files
|
144 | |
(define (main pg file)
|
| 249 |
(define (main pg file out)
|
145 | 250 |
(let* ((page-source (translate-file file))
|
146 | |
(telml (cdr page-source))
|
147 | |
(meta (car page-source))
|
148 | |
(title (if (not (null? meta)) (cadr meta) pg))
|
149 | |
(display (serialize-sxml (page title telml))))
|
150 | |
(format #t "~a\n" display)))
|
| 251 |
(telml (cdr page-source))
|
| 252 |
(meta (car page-source))
|
| 253 |
(date (localtime (stat:mtime (stat file))))
|
| 254 |
(ndate (date->string date))
|
| 255 |
(title (if (not (null? meta)) (meta-title meta) pg))
|
| 256 |
(outfile (if out out
|
| 257 |
(format #f "output/~a/~a/index.html" ndate (meta-slug meta))))
|
| 258 |
(display (sxml->html5 (page title (add-tags telml (meta-tags meta))))))
|
| 259 |
(if (not out)
|
| 260 |
(begin
|
| 261 |
(ensure-folder (format #f "output/~a" ndate))
|
| 262 |
(ensure-folder (format #f "output/~a/~a" ndate (car meta)))))
|
| 263 |
(format #t "printing to ~a\n" outfile)
|
| 264 |
(with-output-to-file outfile
|
| 265 |
(lambda () (format #t "~a\n" display)))))
|
151 | 266 |
|
152 | 267 |
(define (dispatch pg files)
|
153 | 268 |
(cond ((equal? pg "index")
|
154 | |
(with-output-to-file "output/index.html"
|
155 | |
(lambda () (main "index" (car files)))))
|
| 269 |
(main "index" (car files) "output/index.html"))
|
156 | 270 |
((equal? pg "post")
|
157 | |
(with-output-to-file "output/post.html"
|
158 | |
(lambda () (main "post" (car files)))))
|
| 271 |
(map
|
| 272 |
(lambda (f) (main "post" f #f))
|
| 273 |
files))
|
159 | 274 |
((equal? pg "archive")
|
160 | |
(with-output-to-file "output/archive/index.html"
|
161 | |
(lambda () (archive))))
|
| 275 |
(archive))
|
162 | 276 |
((equal? pg "tags")
|
163 | |
(with-output-to-file "output/tags/index.html"
|
164 | |
(lambda () (tags))))
|
| 277 |
(tags))
|
165 | 278 |
((equal? pg "about")
|
166 | |
(with-output-to-file "output/about/index.html"
|
167 | |
(lambda () (main "about" "pages/about.telml"))))))
|
168 | |
|
169 | |
(define args (cdr (command-line)))
|
170 | |
(cond ((= (length args) 0)
|
171 | |
(format #t "Usage: generate [page] [files]\n"))
|
172 | |
(else (dispatch (car args) (cdr args))))
|
| 279 |
(main "about" "pages/about.telml" "output/about/index.html"))))
|
| 280 |
|
| 281 |
(let ((args (cdr (command-line))))
|
| 282 |
(cond ((= (length args) 0)
|
| 283 |
(format #t "Usage: generate [page] [files]\n"))
|
| 284 |
(else (dispatch (car args) (cdr args)))))
|