post: Add metadata parsers.
* haunt/post.scm (%metadata-parsers): New variable. Register parser for 'tags and 'date. (metadata-parser, register-metadata-parser!, parse-metadata): New procedures.
This commit is contained in:
parent
2464d9d06b
commit
84c65348ea
|
@ -25,6 +25,7 @@
|
||||||
(define-module (haunt post)
|
(define-module (haunt post)
|
||||||
#:use-module (srfi srfi-9)
|
#:use-module (srfi srfi-9)
|
||||||
#:use-module (srfi srfi-19)
|
#:use-module (srfi srfi-19)
|
||||||
|
#:use-module (haunt utils)
|
||||||
#:export (make-post
|
#:export (make-post
|
||||||
post?
|
post?
|
||||||
post-file-name
|
post-file-name
|
||||||
|
@ -32,7 +33,10 @@
|
||||||
post-metadata
|
post-metadata
|
||||||
post-ref
|
post-ref
|
||||||
post-slug
|
post-slug
|
||||||
posts/reverse-chronological))
|
posts/reverse-chronological
|
||||||
|
|
||||||
|
register-metdata-parser!
|
||||||
|
parse-metadata))
|
||||||
|
|
||||||
(define-record-type <post>
|
(define-record-type <post>
|
||||||
(make-post file-name metadata sxml)
|
(make-post file-name metadata sxml)
|
||||||
|
@ -61,3 +65,26 @@
|
||||||
(sort posts
|
(sort posts
|
||||||
(lambda (a b)
|
(lambda (a b)
|
||||||
(time>? (post->time a) (post->time b)))))
|
(time>? (post->time a) (post->time b)))))
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; Metadata
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(define %metadata-parsers
|
||||||
|
(make-hash-table))
|
||||||
|
|
||||||
|
(define (metadata-parser key)
|
||||||
|
(or (hash-ref %metadata-parsers key) identity))
|
||||||
|
|
||||||
|
(define (register-metadata-parser! name parser)
|
||||||
|
(hash-set! %metadata-parsers name parser))
|
||||||
|
|
||||||
|
(define (parse-metadata key value)
|
||||||
|
((metadata-parser key) value))
|
||||||
|
|
||||||
|
(register-metadata-parser!
|
||||||
|
'tags
|
||||||
|
(lambda (str)
|
||||||
|
(map string-trim-both (string-split str #\,))))
|
||||||
|
|
||||||
|
(register-metadata-parser! 'date string->date*)
|
||||||
|
|
Loading…
Reference in New Issue