summary refs log tree commit diff stats
path: root/boudin.page.post.scm
diff options
context:
space:
mode:
authorCase Duckworth2023-09-08 08:55:10 -0500
committerCase Duckworth2023-09-08 08:55:10 -0500
commitbb4091acb58f0724dca262bc137715f6ed882e5f (patch)
tree312fb06d53a51094fcdf6b900b4dc1fe327555bc /boudin.page.post.scm
parentA newerer beginning (diff)
downloadboudin-bb4091acb58f0724dca262bc137715f6ed882e5f.tar.gz
boudin-bb4091acb58f0724dca262bc137715f6ed882e5f.zip
1.0, why not
Diffstat (limited to 'boudin.page.post.scm')
-rw-r--r--boudin.page.post.scm77
1 files changed, 77 insertions, 0 deletions
diff --git a/boudin.page.post.scm b/boudin.page.post.scm new file mode 100644 index 0000000..002d7bf --- /dev/null +++ b/boudin.page.post.scm
@@ -0,0 +1,77 @@
1(declare (module (boudin page post))
2 (export make-post
3 post-path-transformers
4 post-text-transformers
5 post-template
6 post-writer))
7
8(import (boudin page)
9 (boudin page write)
10 (boudin site)
11 (boudin util)
12 (chicken pathname)
13 (html-parser)
14 (except (schmaltz)
15 render-specials
16 render-unprintables)
17 (schmaltz chicken)
18 (srfi 152))
19
20(define (make-post path)
21 (let ((sxml ((apply o (post-text-transformers))
22 (with-input-from-file path slurp))))
23 (make-page sxml
24 ((apply o (post-path-transformers)) path)
25 (post-template)
26 (post-writer)
27 (cons (cons "source" path)
28 (*extract-metadata sxml)))))
29
30(define (*extract-metadata sxml)
31 (let loop ((tree sxml)
32 (acc '()))
33 (cond
34 ((not (pair? tree))
35 (reverse acc))
36 ((and (list? (car tree))
37 (eq? (caar tree) '*COMMENT*))
38 (loop (cdr tree)
39 (map (lambda (ln)
40 (let ((kv (string-split ln ":" 'infix 1)))
41 (cons (string-trim-both (car kv))
42 (string-trim (cdr kv)))))
43 (string-split (cadar tree) "\n"))))
44 ((list? (car tree))
45 (loop (cdr tree)
46 (let ((subtree (loop (car tree) '())))
47 (if (null? subtree)
48 acc
49 (cons subtree acc)))))
50 (else (loop (cdr tree) acc)))))
51
52(define post-text-transformers
53 (make-parameter
54 (list html->sxml
55 wrap-paragraphs
56 render-string->string)))
57
58(define post-path-transformers
59 (make-parameter
60 (list (lambda (path)
61 (make-pathname (list (site-output)
62 (pathname-strip-extension path))
63 "index.html")))))
64
65(define post-template
66 (make-parameter
67 (lambda (pg)
68 (let ((title (page-ref pg "title")))
69 `(html (@ (lang "en-us"))
70 (head ,@(html-head)
71 (title ,(or title "[untitled]")))
72 (body ,(if title `(h1 ,title) "")
73 ,@(cdr (page-content pg))))))))
74
75(define post-writer
76 (make-parameter
77 sxml-display-as-html))