aboutsummaryrefslogtreecommitdiff
path: root/haunt/custom/tag.scm
diff options
context:
space:
mode:
authorJakob L. Kreuze2019-05-10 19:07:03 -0400
committerJakob L. Kreuze2019-05-10 19:07:03 -0400
commiteceaf45e8c353c8cfd2ae88f39f523f028509a0c (patch)
treec62dfee90df4e31b0a8ded6662cdd1a512d382d5 /haunt/custom/tag.scm
parent2eec3c376a72c7edf8ae363cc11c8abe0d118b35 (diff)
Create a page listing all tags
Diffstat (limited to 'haunt/custom/tag.scm')
-rw-r--r--haunt/custom/tag.scm27
1 files changed, 26 insertions, 1 deletions
diff --git a/haunt/custom/tag.scm b/haunt/custom/tag.scm
index abac1b5..c8a0337 100644
--- a/haunt/custom/tag.scm
+++ b/haunt/custom/tag.scm
@@ -20,7 +20,32 @@
#:use-module (haunt html)
#:use-module (haunt page)
#:use-module (haunt post)
- #:export (sort-by-tag))
+ #:export (all-tags
+ sort-by-tag))
+
+(define (tag-counts posts)
+ "Return an alist of every tag used in POSTS paired with the number of times it
+is used."
+ (sort (map (lambda (tag) (cons (car tag) (length (cdr tag))))
+ (posts/group-by-tag posts))
+ (lambda (a b) (> (cdr a) (cdr b)))))
+
+(define (format-tag pair)
+ "Return an SXML expression for the tag-count pair."
+ (let* ((tag (car pair))
+ (count (cdr pair))
+ (target (format #f "/tag-~a.html" tag)))
+ `(p (a (@ (href ,target)) ,tag)
+ ,(format #f " (~a)" count))))
+
+(define (all-tags)
+ "Return a procedure creating a page listing all of the tags used in the blog."
+ (lambda (site posts)
+ (let ((body (append `((h1 "All Tags"))
+ (map format-tag (tag-counts posts)))))
+ (make-page "tags.html"
+ (with-layout jakob-theme site "All Tags" body)
+ sxml->html))))
(define (sort-by-tag)
"Return a procedure that transforms a list of posts into pages containing only

© 2015 - 2026 Jakob L. Kreuze