summary refs log tree commit diff stats
path: root/boudin.scm
diff options
context:
space:
mode:
authorCase Duckworth2023-07-23 11:21:38 -0500
committerCase Duckworth2023-07-23 11:21:38 -0500
commit93ffa999444dfd01672a2bc88ec9d1b4a5f9c368 (patch)
treeb7422fe8a5470c526eca7644c3d474727b09e967 /boudin.scm
parentMake my own atom file with CDATA and blow (diff)
downloadboudin-93ffa999444dfd01672a2bc88ec9d1b4a5f9c368.tar.gz
boudin-93ffa999444dfd01672a2bc88ec9d1b4a5f9c368.zip
Use slugs
Diffstat (limited to 'boudin.scm')
-rwxr-xr-xboudin.scm30
1 files changed, 24 insertions, 6 deletions
diff --git a/boudin.scm b/boudin.scm index 3ace3e6..f746f24 100755 --- a/boudin.scm +++ b/boudin.scm
@@ -46,6 +46,14 @@ boudin --- a little static site generator
46 "index" 46 "index"
47 "html")) 47 "html"))
48 48
49(define (slugify path)
50 (transform path
51 normalize-pathname
52 ;; XXX: this should be much more robust
53 (lambda (p) (pathname-replace-directory p "/"))
54 pathname-strip-extension
55 (lambda (p) (string-append p "/"))))
56
49(define (transform-path path outdir) #| path => path 57(define (transform-path path outdir) #| path => path
50 Transform PATH according to boudin's needs. |# 58 Transform PATH according to boudin's needs. |#
51 (transform path 59 (transform path
@@ -152,15 +160,21 @@ boudin --- a little static site generator
152;; It also includes the extracted metadata from the page for processing. 160;; It also includes the extracted metadata from the page for processing.
153 161
154(define-record-type <page> 162(define-record-type <page>
155 (make-page url meta source dest source-path dest-path) 163 (make-page slug meta source dest source-path dest-path)
156 page? 164 page?
157 (url page-url (setter page-url)) 165 (slug page-slug (setter page-slug))
158 (meta page-meta (setter page-meta)) 166 (meta page-meta (setter page-meta))
159 (source page-source) 167 (source page-source)
160 (dest page-dest (setter page-dest)) 168 (dest page-dest (setter page-dest))
161 (source-path page-source-path) 169 (source-path page-source-path)
162 (dest-path page-dest-path (setter page-dest-path))) 170 (dest-path page-dest-path (setter page-dest-path)))
163 171
172(define (page-url page)
173 (normalize-pathname
174 (make-pathname (list (site-base-url)
175 (page-slug page))
176 #f)))
177
164(define (%read-port port) #| port -> string 178(define (%read-port port) #| port -> string
165 Read PORT until it hits eof and return the results as a string. 179 Read PORT until it hits eof and return the results as a string.
166 |# 180 |#
@@ -196,7 +210,7 @@ boudin --- a little static site generator
196 page's metadata, too. |# 210 page's metadata, too. |#
197 (let* ((source (with-input-from-file file read-port)) 211 (let* ((source (with-input-from-file file read-port))
198 (dest (html->sxml (transform-content source)))) 212 (dest (html->sxml (transform-content source))))
199 (make-page (pathname-directory (transform-path file (site-base-url))) 213 (make-page (slugify file)
200 (extract-meta dest) 214 (extract-meta dest)
201 source 215 source
202 dest 216 dest
@@ -310,11 +324,12 @@ boudin --- a little static site generator
310 (body (h1 ,(site-name)) 324 (body (h1 ,(site-name))
311 (ul 325 (ul
312 ,@(map (lambda (pg) 326 ,@(map (lambda (pg)
313 `(li (a (@ (href ,(page-url pg))) 327 `(li (a (@ (href ,(page-slug pg)))
314 ,(page-meta-ref pg 328 ,(page-meta-ref pg
315 "title" 329 "title"
316 (pathname-file 330 (pathname-file
317 (page-source-path pg)))))) 331 (page-source-path pg))))))
332 ;; TODO : sort pages
318 pages))))))) 333 pages)))))))
319 334
320(define feed-template 335(define feed-template
@@ -464,8 +479,8 @@ boudin --- a little static site generator
464 ;; Operand proc (operand seeds ...) 479 ;; Operand proc (operand seeds ...)
465 (lambda (name seeds) 480 (lambda (name seeds)
466 (if (file-exists? name) 481 (if (file-exists? name)
467 (set! pages (cons (file->page name) pages)) 482 (set! pages (cons name pages))
468 (die 2 "Page not found: " name)) 483 (die 2 "File not found: " name))
469 seeds) 484 seeds)
470 ;; Seeds 485 ;; Seeds
471 '()) 486 '())
@@ -484,6 +499,9 @@ boudin --- a little static site generator
484 (load (build-config)) 499 (load (build-config))
485 (print-log "No config.scm found; using default config")) 500 (print-log "No config.scm found; using default config"))
486 (create-directory (build-directory) 'parents) 501 (create-directory (build-directory) 'parents)
502 ;; Convert pages to sxml. This needs to be done here because config.scm
503 ;; might define functions used by the pages.
504 (pages (map file->page (pages)))
487 ;; Build the site 505 ;; Build the site
488 (write-style) ; TODO: copy static assets (?) 506 (write-style) ; TODO: copy static assets (?)
489 (for-each write-page (pages)) 507 (for-each write-page (pages))