added poems and redesigned
This commit is contained in:
40
compile.zp
40
compile.zp
@@ -4,28 +4,48 @@
|
||||
(import-all "mustache")
|
||||
(import-all "pandoc")
|
||||
|
||||
(define tpl (read-contents "layout.html"))
|
||||
(define post-tpl (read-contents "post.html"))
|
||||
(define list-tpl (read-contents "list.html"))
|
||||
(define poem-dir "poems/")
|
||||
(define out-dir "out/")
|
||||
|
||||
(define (all-poems)
|
||||
(define (all-sites)
|
||||
(let* ((ls (os:ls poem-dir))
|
||||
(ls (filter ($ (not (in? ["." ".."] %))) ls)))
|
||||
(map (curry ++ poem-dir) ls)))
|
||||
ls))
|
||||
|
||||
(define (from-path file)
|
||||
(regex:sub r/.md$/ "" (list:last (string:split file "/"))))
|
||||
(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 targets)
|
||||
(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 "index.html"
|
||||
(curry write (mustache:template tpl args)))))
|
||||
(with-output-file name
|
||||
(curry write (mustache:template post-tpl args)))))
|
||||
|
||||
(let ((targets (all-poems)))
|
||||
(render targets))
|
||||
(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))
|
||||
|
Reference in New Issue
Block a user