aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob/utils.scm
diff options
context:
space:
mode:
Diffstat (limited to 'haunt/jakob/utils.scm')
-rw-r--r--haunt/jakob/utils.scm22
1 files changed, 12 insertions, 10 deletions
diff --git a/haunt/jakob/utils.scm b/haunt/jakob/utils.scm
index a104510..ad35f4c 100644
--- a/haunt/jakob/utils.scm
+++ b/haunt/jakob/utils.scm
@@ -19,7 +19,8 @@
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
- #:export (maybe-cons*
+ #:export (assq-map!
+ maybe-cons*
maybe-list
date->string*
intersperse
@@ -28,6 +29,12 @@
elide-string))
+(define (assq-map! alist key fn)
+ "Destructively apply FN to KEY in ALIST, if it exists"
+ (match (assq-ref alist key)
+ (#f alist)
+ (val (assq-set! alist key (fn val)))))
+
(define (maybe-list . args)
"Create a list of all ARGS that are neither #f nor unspecified."
(remove (lambda (element)
@@ -62,16 +69,11 @@ is of an odd length and every second element is DELIM."
content)))
(define (first-paragraph post)
- (let loop ((sxml (post-sxml post))
- (result '()))
+ (let loop ((sxml (post-sxml post)))
(match sxml
- (() (remove-footnote-references (reverse result)))
- ((or (('p ...) tail ...) (paragraph tail ...))
- (if (and (list? paragraph) (eqv? 'header (car paragraph)))
- (loop tail result) ; Ignore front-matter.
- (remove-footnote-references (reverse (cons paragraph result)))))
- ((head . tail)
- (loop tail (cons head result))))))
+ (((and ('p content ...) paragraph) . tail)
+ (remove-footnote-references paragraph))
+ ((head . tail) (loop tail)))))
(define (description-from-post post)
(define (first-elem sxml)

© 2015 - 2026 Jakob L. Kreuze