diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-04-11 14:51:44 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-04-11 15:10:45 -0400 |
commit | 4d99832b6befd10779b6a6fde0568cbc376e3685 (patch) | |
tree | 5f41a51c8a4a10dc3f2e836eceabfe49fd9d4591 | |
parent | a45269f52365ce15f74c7998343f6d03fc7f8871 (diff) |
reader: Add read-posts procedure.
* haunt/reader.scm (read-posts): New procedure.
-rw-r--r-- | haunt/reader.scm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/haunt/reader.scm b/haunt/reader.scm index fe13456..05aed8c 100644 --- a/haunt/reader.scm +++ b/haunt/reader.scm @@ -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 ;;; |