From 93ffa999444dfd01672a2bc88ec9d1b4a5f9c368 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 23 Jul 2023 11:21:38 -0500 Subject: Use slugs --- boudin.scm | 30 ++++++++++++++++++++++++------ 1 file 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 "index" "html")) +(define (slugify path) + (transform path + normalize-pathname + ;; XXX: this should be much more robust + (lambda (p) (pathname-replace-directory p "/")) + pathname-strip-extension + (lambda (p) (string-append p "/")))) + (define (transform-path path outdir) #| path => path Transform PATH according to boudin's needs. |# (transform path @@ -152,15 +160,21 @@ boudin --- a little static site generator ;; It also includes the extracted metadata from the page for processing. (define-record-type - (make-page url meta source dest source-path dest-path) + (make-page slug meta source dest source-path dest-path) page? - (url page-url (setter page-url)) + (slug page-slug (setter page-slug)) (meta page-meta (setter page-meta)) (source page-source) (dest page-dest (setter page-dest)) (source-path page-source-path) (dest-path page-dest-path (setter page-dest-path))) +(define (page-url page) + (normalize-pathname + (make-pathname (list (site-base-url) + (page-slug page)) + #f))) + (define (%read-port port) #| port -> string Read PORT until it hits eof and return the results as a string. |# @@ -196,7 +210,7 @@ boudin --- a little static site generator page's metadata, too. |# (let* ((source (with-input-from-file file read-port)) (dest (html->sxml (transform-content source)))) - (make-page (pathname-directory (transform-path file (site-base-url))) + (make-page (slugify file) (extract-meta dest) source dest @@ -310,11 +324,12 @@ boudin --- a little static site generator (body (h1 ,(site-name)) (ul ,@(map (lambda (pg) - `(li (a (@ (href ,(page-url pg))) + `(li (a (@ (href ,(page-slug pg))) ,(page-meta-ref pg "title" (pathname-file (page-source-path pg)))))) + ;; TODO : sort pages pages))))))) (define feed-template @@ -464,8 +479,8 @@ boudin --- a little static site generator ;; Operand proc (operand seeds ...) (lambda (name seeds) (if (file-exists? name) - (set! pages (cons (file->page name) pages)) - (die 2 "Page not found: " name)) + (set! pages (cons name pages)) + (die 2 "File not found: " name)) seeds) ;; Seeds '()) @@ -484,6 +499,9 @@ boudin --- a little static site generator (load (build-config)) (print-log "No config.scm found; using default config")) (create-directory (build-directory) 'parents) + ;; Convert pages to sxml. This needs to be done here because config.scm + ;; might define functions used by the pages. + (pages (map file->page (pages))) ;; Build the site (write-style) ; TODO: copy static assets (?) (for-each write-page (pages)) -- cgit 1.4.1-21-gabe81