From eceaf45e8c353c8cfd2ae88f39f523f028509a0c Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Fri, 10 May 2019 19:07:03 -0400 Subject: Create a page listing all tags --- haunt/custom/tag.scm | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'haunt/custom/tag.scm') 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 -- cgit v1.3