summary refs log tree commit diff stats
path: root/boudin.page.scm
diff options
context:
space:
mode:
authorCase Duckworth2023-09-06 22:45:45 -0500
committerCase Duckworth2023-09-06 22:45:45 -0500
commit59598f42c16cf12e544e5bf2ce9c873fba94238e (patch)
tree055f106b72f289f59d4af417a24448e4983dbec3 /boudin.page.scm
parentA new start (again) (diff)
downloadboudin-59598f42c16cf12e544e5bf2ce9c873fba94238e.tar.gz
boudin-59598f42c16cf12e544e5bf2ce9c873fba94238e.zip
A newerer beginning
Diffstat (limited to 'boudin.page.scm')
-rw-r--r--boudin.page.scm78
1 files changed, 78 insertions, 0 deletions
diff --git a/boudin.page.scm b/boudin.page.scm new file mode 100644 index 0000000..004e750 --- /dev/null +++ b/boudin.page.scm
@@ -0,0 +1,78 @@
1(declare (module (boudin page))
2 (export make-page
3 page-content
4 page-meta
5 page-meta-set!
6 page-output
7 page-ref
8 page-set!
9 page-slug
10 page-template
11 page-updated
12 page-url
13 page-writer
14 page?)
15 (import (boudin site)
16 (boudin util)
17 (chicken file posix)
18 (chicken file)
19 (chicken pathname)
20 (chicken time posix)
21 (srfi 1)))
22
23(define-record-type page
24 (make-page content output template writer meta)
25 page?
26 (content page-content)
27 (output page-output)
28 (template page-template)
29 (writer page-writer)
30 (meta page-meta page-meta-set!))
31
32(define (page-ref pg k)
33 (assoc-ref k (or (page-meta pg) '())))
34
35(define (page-set! pg k v)
36 (page-meta-set! pg (cons (cons k v)
37 (page-meta pg))))
38
39(define (*urlify path)
40 (normalize-pathname
41 (make-pathname (list (string-append "https://" (site-host))
42 (pathname-strip-extension path))
43 "index.html")))
44
45(define (page-url pg) ; foo.html => http://site.com/foo/index.html
46 (or (page-ref pg "url") ; memoization
47 (let ((url (*urlify (page-ref pg "source"))))
48 (page-set! pg "url" url)
49 url)))
50
51(define (*slugify url) ; I don't love how this is written..
52 (let-values (((_ _ dirs) (decompose-directory url)))
53 (let loop ((this (car dirs))
54 (rest (cdr dirs)))
55 (if (null? (cdr rest))
56 (make-pathname (list "/" this) #f)
57 (loop (car rest)
58 (cdr rest))))))
59
60(define (page-slug pg) ; http://site.com/foo/index.html => /foo/
61 (or (page-ref pg "slug") ; memoization
62 (let ((slug (*slugify (page-url pg))))
63 (page-set! pg "slug" slug)
64 slug)))
65
66(define (*page-mtime pg)
67 (let ((file (page-ref pg "source")))
68 (and file
69 (file-exists? file)
70 (time->string (seconds->utc-time (file-modification-time file))))))
71
72(define (page-updated pg)
73 (let ((meta-date (page-ref pg "date")))
74 (or (and meta-date ; memoization
75 (find (lambda (fmt) (string->time meta-date fmt))
76 (site-date-formats)))
77 (*page-mtime pg)
78 (site-build-time))))