summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-04-11 22:28:07 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-04-11 22:33:54 -0400
commit2464d9d06bff64328c7812ff820101f8d4335e77 (patch)
tree8b8548ff94cbdad3f4f60103bdb00b1b4a912c98
parentc2191a68f2855c03894d2267ff9853b1f02ba039 (diff)
post: Add helper procedures.
* haunt/post.scm (post-slug, posts/reverse-chronological): New procedures.
-rw-r--r--haunt/post.scm22
1 files changed, 21 insertions, 1 deletions
diff --git a/haunt/post.scm b/haunt/post.scm
index a9d03ea..3d2359e 100644
--- a/haunt/post.scm
+++ b/haunt/post.scm
@@ -24,12 +24,15 @@
(define-module (haunt post)
#:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-19)
#:export (make-post
post?
post-file-name
post-sxml
post-metadata
- post-ref))
+ post-ref
+ post-slug
+ posts/reverse-chronological))
(define-record-type <post>
(make-post file-name metadata sxml)
@@ -41,3 +44,20 @@
(define (post-ref post key)
"Return the metadata corresponding to KEY within POST."
(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)))))