52 lines
1.5 KiB
Plaintext
52 lines
1.5 KiB
Plaintext
(load "mustache/mustache")
|
|
(load "pandoc/pandoc")
|
|
|
|
(import-all "mustache")
|
|
(import-all "pandoc")
|
|
|
|
(define post-tpl (read-contents "post.html"))
|
|
(define list-tpl (read-contents "list.html"))
|
|
(define poem-dir "poems/")
|
|
(define out-dir "out/")
|
|
|
|
(define (all-sites)
|
|
(let* ((ls (os:ls poem-dir))
|
|
(ls (filter ($ (not (in? ["." ".."] %))) ls)))
|
|
ls))
|
|
|
|
(define (all-poems elem)
|
|
(let* ((dir (++ poem-dir elem "/"))
|
|
(ls (os:ls dir))
|
|
(ls (filter ($ (not (in? ["." ".."] %))) ls)))
|
|
(map (curry ++ dir) ls)))
|
|
|
|
(define (filename file)
|
|
(list:last (string:split file "/")))
|
|
|
|
(define (treat str)
|
|
(regex:gsub r/<br \/>/ "</p><p>" (regex:gsub r/<p>/ "<p class='paragraph'>" str)))
|
|
|
|
(define (render name targets)
|
|
(let* ((strs (map read-contents targets))
|
|
(args (make-hash
|
|
"poems" (map (compose treat
|
|
(curry pandoc:convert "markdown" "html"))
|
|
strs))))
|
|
(with-output-file name
|
|
(curry write (mustache:template post-tpl args)))))
|
|
|
|
(define (make-index elems)
|
|
(let ((names (map ($ (make-hash
|
|
"name" (regex:gsub r/_/ " " %)
|
|
"url" (++ % ".html")))
|
|
elems)))
|
|
(with-output-file "index.html"
|
|
(curry write (mustache:template list-tpl (make-hash "names" names))))))
|
|
|
|
(let ((elems (all-sites)))
|
|
(map (lambda (elem)
|
|
(let ((targets (all-poems elem)))
|
|
(render (++ out-dir elem ".html") targets)))
|
|
elems)
|
|
(make-index elems))
|