Skip to content

Commit

Permalink
Support tags list on the tags index pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Apr 29, 2024
1 parent 8f9f270 commit 3a0eff9
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/index/tags.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(uiop:define-package #:staticl/index/tags
(:use #:cl)
(:import-from #:staticl/index/base
#:page-target-path
#:page-size
#:index-target-path
#:index-page
Expand Down Expand Up @@ -100,6 +101,13 @@
(:documentation "A tag bound to the index page. A URL for such tags will lead to the index page."))


(defmethod print-object ((tag bound-tag) stream)
(print-unreadable-object (tag stream :type t)
(format stream "\"~A\" ~S"
(tag-name tag)
(tag-index-page tag))))


(-> upgrade-tag (string index-page content-with-tags-mixin)
(values &optional))

Expand All @@ -119,6 +127,26 @@
(values hash)))


(defclass tags-index-page (index-page)
((all-tags :initarg :all-tags
:initform nil
:accessor all-tags)))


(defmethod print-object ((page tags-index-page) stream)
(print-unreadable-object (page stream :type t)
(format stream "\"~A\""
(page-target-path page))))


(defmethod template-vars ((site site) (page tags-index-page) &key (hash (dict)))
(let ((hash (call-next-method site page :hash hash)))
(setf (gethash "tags" hash)
(mapcar (curry #'template-vars site)
(all-tags page)))
(values hash)))


(defmethod staticl/pipeline:process-items ((site site) (index tags-index) content-items)
"Here we are grouping all posts by their tags, generate an index page for each tag and upgrade tag instances to the tags bound to their corresponding index pages.
Expand All @@ -137,7 +165,7 @@
using (hash-value tagged-posts)
for sorted-posts = (sort tagged-posts #'string<
:key #'content-title)
for index-page = (make-instance 'index-page
for index-page = (make-instance 'tags-index-page
:title (funcall (page-title-fn index)
tag-name)
:target-path (merge-pathnames
Expand All @@ -153,5 +181,12 @@
(mapc (curry #'upgrade-tag
tag-name
index-page)
sorted-posts)))
sorted-posts)
collect (make-instance 'bound-tag
:name tag-name
:index-page index-page) into all-tags
finally (loop for tag in all-tags
for index-page = (tag-index-page tag)
do (setf (all-tags index-page)
all-tags))))
(values))

0 comments on commit 3a0eff9

Please sign in to comment.