post: Add helper procedures.
* haunt/post.scm (post-slug, posts/reverse-chronological): New procedures.
This commit is contained in:
parent
c2191a68f2
commit
2464d9d06b
|
@ -24,12 +24,15 @@
|
||||||
|
|
||||||
(define-module (haunt post)
|
(define-module (haunt post)
|
||||||
#:use-module (srfi srfi-9)
|
#:use-module (srfi srfi-9)
|
||||||
|
#:use-module (srfi srfi-19)
|
||||||
#:export (make-post
|
#:export (make-post
|
||||||
post?
|
post?
|
||||||
post-file-name
|
post-file-name
|
||||||
post-sxml
|
post-sxml
|
||||||
post-metadata
|
post-metadata
|
||||||
post-ref))
|
post-ref
|
||||||
|
post-slug
|
||||||
|
posts/reverse-chronological))
|
||||||
|
|
||||||
(define-record-type <post>
|
(define-record-type <post>
|
||||||
(make-post file-name metadata sxml)
|
(make-post file-name metadata sxml)
|
||||||
|
@ -41,3 +44,20 @@
|
||||||
(define (post-ref post key)
|
(define (post-ref post key)
|
||||||
"Return the metadata corresponding to KEY within POST."
|
"Return the metadata corresponding to KEY within POST."
|
||||||
(assq-ref (post-metadata post) key))
|
(assq-ref (post-metadata post) key))
|
||||||
|
|
||||||
|
(define (post-slug post)
|
||||||
|
"Transform the title of POST into a URL slug."
|
||||||
|
(string-join (map (lambda (s)
|
||||||
|
(string-filter char-set:letter+digit s))
|
||||||
|
(string-split (string-downcase (post-ref post 'title))
|
||||||
|
char-set:whitespace))
|
||||||
|
"-"))
|
||||||
|
|
||||||
|
(define (post->time post)
|
||||||
|
(date->time-utc (post-ref post 'date)))
|
||||||
|
|
||||||
|
(define (posts/reverse-chronological posts)
|
||||||
|
"Returns POSTS sorted in reverse chronological order."
|
||||||
|
(sort posts
|
||||||
|
(lambda (a b)
|
||||||
|
(time>? (post->time a) (post->time b)))))
|
||||||
|
|
Loading…
Reference in New Issue