diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-10-15 22:46:30 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-10-15 22:46:30 -0400 |
commit | dfad89079b64b97e099f6d86e44b6d9deb76a5d5 (patch) | |
tree | ec838586a4d43f76bf91eb2e687111d36a1fcedf /haunt/post.scm | |
parent | e505a66a1b22132fd429c7699b7b632143d6653c (diff) |
post: Add read-metadata-headers procedure.
* haunt/post.scm (read-metadata-headers): New procedure.
* haunt/reader.scm (read-html-post): Reimplement using
'read-metadata-headers'.
* tests/post.scm (%tzoffset): New variable.
("read-metadata-headers"): New test.
Diffstat (limited to 'haunt/post.scm')
-rw-r--r-- | haunt/post.scm | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/haunt/post.scm b/haunt/post.scm index 361fd6d..47aaa55 100644 --- a/haunt/post.scm +++ b/haunt/post.scm @@ -23,6 +23,8 @@ ;;; Code: (define-module (haunt post) + #:use-module (ice-9 match) + #:use-module (ice-9 rdelim) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (srfi srfi-19) @@ -40,7 +42,8 @@ posts/group-by-tag register-metdata-parser! - parse-metadata)) + parse-metadata + read-metadata-headers)) (define-record-type <post> (make-post file-name metadata sxml) @@ -107,6 +110,20 @@ specified." (define (parse-metadata key value) ((metadata-parser key) value)) +(define (read-metadata-headers port) + (let loop ((metadata '())) + (let ((line (read-line port))) + (cond + ((eof-object? line) + (error "end of file while reading metadata: " (port-filename port))) + ((string=? line "---") + metadata) + (else + (match (map string-trim-both (string-split-at line #\:)) + (((= string->symbol key) value) + (loop (alist-cons key (parse-metadata key value) metadata))) + (_ (error "invalid metadata format: " line)))))))) + (register-metadata-parser! 'tags (lambda (str) |