From 61d3b6aae43e1ad870e7832ec964964124eacb1b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 15 Sep 2023 00:19:37 -0500 Subject: Fix bugs and implement changes I can actually build a (one-page) site! --- boudin.config.scm | 22 ++++++++++++++++++++++ boudin.egg | 11 +++++++++-- boudin.page.index.scm | 5 +++++ boudin.page.post.scm | 16 ++++++++++------ boudin.scm | 9 +++++---- boudin.site.scm | 2 +- boudin.util.scm | 8 ++++++++ 7 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 boudin.config.scm diff --git a/boudin.config.scm b/boudin.config.scm new file mode 100644 index 0000000..2cc5892 --- /dev/null +++ b/boudin.config.scm @@ -0,0 +1,22 @@ +(module (boudin config) () + (import scheme (chicken module)) + (reexport (except (boudin site) + site-build-time) + (boudin util) + (only (boudin page style) + style-template + site-style + style-writer) + (only (boudin page post) + post-text-transformers + post-path-transformers + post-template + post-writer) + (only (boudin page write) + html-head) ; TODO: move to boudin.page + (only (boudin page index) + index-content + index-writer + index-template + feed-writer + feed-template))) diff --git a/boudin.egg b/boudin.egg index b7eb4d3..daac0ac 100644 --- a/boudin.egg +++ b/boudin.egg @@ -1,9 +1,9 @@ ;;; boudin -((synopsis "a tiny, tasty ssg.") +((synopsis "a spicy, tasty ssg.") (author "Case Duckworth") (license "God Willing") - (version 1.0) + (version 0.9) ; almost done! (build-dependencies module-declarations) (dependencies atom html-parser @@ -25,6 +25,13 @@ boudin.page.write boudin.site boudin.util)) + (extension boudin.config + (component-dependencies boudin.site + boudin.page.style + boudin.page.post + boudin.page.index + boudin.page.write + boudin.util)) (extension boudin.page (component-dependencies boudin.site boudin.util)) diff --git a/boudin.page.index.scm b/boudin.page.index.scm index 4ff3fd9..52aebc8 100644 --- a/boudin.page.index.scm +++ b/boudin.page.index.scm @@ -1,5 +1,6 @@ (declare (module (boudin page index)) (export make-index + index-content index-template index-writer make-feed @@ -33,12 +34,16 @@ (head ,@(html-head) (title ,(site-name))) (body (h1 ,(site-name)) + ,(index-content) (ul ,@(map (lambda (pg) `(li (a (@ (href ,(page-slug pg))) ,(or (page-ref pg "title") (page-slug pg))))) ((site-sort) pgs)))))))) +(define index-content + (make-parameter "")) + (define (make-feed pgs) (make-page ((feed-template) pgs) (make-pathname (site-output) "feed.xml") diff --git a/boudin.page.post.scm b/boudin.page.post.scm index 002d7bf..bd77695 100644 --- a/boudin.page.post.scm +++ b/boudin.page.post.scm @@ -15,6 +15,7 @@ render-specials render-unprintables) (schmaltz chicken) + (srfi 1) (srfi 152)) (define (make-post path) @@ -30,17 +31,20 @@ (define (*extract-metadata sxml) (let loop ((tree sxml) (acc '())) + ;;; CONSIDER: using `read' to simplify this crazy logic (cond - ((not (pair? tree)) + ((null? tree) (reverse acc)) ((and (list? (car tree)) (eq? (caar tree) '*COMMENT*)) (loop (cdr tree) - (map (lambda (ln) - (let ((kv (string-split ln ":" 'infix 1))) - (cons (string-trim-both (car kv)) - (string-trim (cdr kv))))) - (string-split (cadar tree) "\n")))) + (filter-map (lambda (ln) + (let ((kv (string-split ln ":" 'infix 1))) + (and (pair? kv) + (cons (string-trim-both (car kv)) + (apply string-append + (map string-trim (cdr kv))))))) + (string-split (cadar tree) "\n")))) ((list? (car tree)) (loop (cdr tree) (let ((subtree (loop (car tree) '()))) diff --git a/boudin.scm b/boudin.scm index b56b93b..9135a9e 100644 --- a/boudin.scm +++ b/boudin.scm @@ -11,6 +11,8 @@ (chicken pathname) (chicken process-context)) +;; State variables + (define site-posts (make-parameter '())) @@ -28,9 +30,6 @@ (define (go!) (eprint "Building " (site-name) "...") - (when (file-exists? (site-config)) - (with-progress (string-append "Config found, loading: " (site-config)) - (lambda () (load (site-config))))) (for-each (lambda (f) (with-progress (string-append "Copying " f " to " (site-output)) (lambda () (copy-static f)))) (site-files)) @@ -52,7 +51,9 @@ (let loop ((args args)) (cond ((null? args) - (for-each print (site-posts)) + (when (file-exists? (site-config)) + (with-progress (string-append "Loading " (site-config)) + (lambda () (load (site-config))))) (go!)) ;; Configuration file: -c FILE ((equal? (car args) "-c") diff --git a/boudin.site.scm b/boudin.site.scm index ee94b9b..a345338 100644 --- a/boudin.site.scm +++ b/boudin.site.scm @@ -39,7 +39,7 @@ (make-parameter '("%Y-%m-%d" "%d/%m/%Y"))) -;; State variables +;;; State (define site-build-time (make-parameter diff --git a/boudin.util.scm b/boudin.util.scm index b5c3efe..916dbf1 100644 --- a/boudin.util.scm +++ b/boudin.util.scm @@ -1,12 +1,14 @@ (declare (module (boudin util)) (export assoc-ref slurp + slurp-bytes wrap-paragraphs edisplay eprint)) (import (chicken io) (srfi 1) + (srfi 4) (srfi 152)) (define (edisplay x) @@ -61,3 +63,9 @@ ((port) (read-string #f port) ; CHICKEN-ism ))) + +(define slurp-bytes + (case-lambda + (() (slurp-bytes (current-input-port))) + ((port) + (read-u8vector #f port)))) -- cgit 1.4.1-21-gabe81