reader: Add read-posts procedure.

* haunt/reader.scm (read-posts): New procedure.
This commit is contained in:
David Thompson 2015-04-11 14:51:44 -04:00
parent a45269f523
commit 4d99832b6b
1 changed files with 21 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (ice-9 ftw)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
#:use-module (ice-9 rdelim)
@ -38,6 +39,7 @@
reader-proc
reader-match?
read-post
read-posts
make-file-extension-matcher
sxml-reader))
@ -60,6 +62,25 @@ metadata with DEFAULT-METADATA."
(append metadata default-metadata)
sxml)))
(define* (read-posts directory readers #:optional (default-metadata '()))
"Read all of the files in DIRECTORY as post objects. The READERS
list must contain a matching reader for every post."
(define enter? (const #t))
(define (leaf file-name stat memo)
(let ((reader (find (cut reader-match? <> file-name) readers)))
(if reader
(cons (read-post reader file-name default-metadata) memo)
(error "no reader available for post: " file-name))))
(define (noop file-name stat result)
result)
(define (err file-name stat errno result)
(error "file processing failed with errno: " file-name errno))
(file-system-fold enter? leaf noop noop noop err '() directory))
;;;
;;; Simple readers
;;;