reader: Add read-posts procedure.
* haunt/reader.scm (read-posts): New procedure.
This commit is contained in:
parent
a45269f523
commit
4d99832b6b
|
@ -27,6 +27,7 @@
|
||||||
#:use-module (srfi srfi-9)
|
#:use-module (srfi srfi-9)
|
||||||
#:use-module (srfi srfi-11)
|
#:use-module (srfi srfi-11)
|
||||||
#:use-module (srfi srfi-26)
|
#:use-module (srfi srfi-26)
|
||||||
|
#:use-module (ice-9 ftw)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 regex)
|
#:use-module (ice-9 regex)
|
||||||
#:use-module (ice-9 rdelim)
|
#:use-module (ice-9 rdelim)
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
reader-proc
|
reader-proc
|
||||||
reader-match?
|
reader-match?
|
||||||
read-post
|
read-post
|
||||||
|
read-posts
|
||||||
|
|
||||||
make-file-extension-matcher
|
make-file-extension-matcher
|
||||||
sxml-reader))
|
sxml-reader))
|
||||||
|
@ -60,6 +62,25 @@ metadata with DEFAULT-METADATA."
|
||||||
(append metadata default-metadata)
|
(append metadata default-metadata)
|
||||||
sxml)))
|
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
|
;;; Simple readers
|
||||||
;;;
|
;;;
|
||||||
|
|
Loading…
Reference in New Issue