summary refs log tree commit diff stats
path: root/boudin.page.instances.scm
diff options
context:
space:
mode:
Diffstat (limited to 'boudin.page.instances.scm')
-rw-r--r--boudin.page.instances.scm79
1 files changed, 79 insertions, 0 deletions
diff --git a/boudin.page.instances.scm b/boudin.page.instances.scm new file mode 100644 index 0000000..1a3a12e --- /dev/null +++ b/boudin.page.instances.scm
@@ -0,0 +1,79 @@
1(declare (module (boudin page instances))
2 (export make-feed
3 make-index
4 make-post
5 post-path-transformers
6 post-text-transformers))
7
8(import (boudin page write)
9 (boudin page)
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 (make-index pgs)
53 (make-page ((index-template) pgs)
54 (make-pathname (site-output) "index.html")
55 page-content
56 (index-writer)
57 `()))
58
59(define (make-feed pgs)
60 (make-page ((feed-template) pgs)
61 (make-pathname (site-output) "feed.xml")
62 page-content
63 (feed-writer)
64 `()))
65
66;; Configurables
67
68(define post-text-transformers
69 (make-parameter
70 (list html->sxml
71 wrap-paragraphs
72 render-string->string)))
73
74(define post-path-transformers
75 (make-parameter
76 (list (lambda (path)
77 (make-pathname (list (site-output)
78 (pathname-strip-extension path))
79 "index.html")))))