src/view/admin/post-list.lisp
(in-package :murja.view.admin.post-list)
(defun admin-post-row (title-to-print)
(with-slots (title month year id tags hidden unlisted) title-to-print
(with-html
(:div.title-flex-container
(:span.post-admin-title (format nil "~a - ~a ~d" title month year))
(:a :href
(murja.genurl:route->url 'murja.view.admin.new-post:blog/post/editor :id id)
"Edit")
(:div.post-admin-title
(:h* "Tags")
(:ul
(dolist (tag tags)
(:li
;; TODO NOT IMPLEMENTED
(:a :href (format nil "/blog/tags/~a" tag) tag)))))))))
(defun tagcloud ()
(let* ((all-tags
(postmodern:query "select distinct (replace((elements->0)::text, '\"', ''))
from blog.post as orig_post,
jsonb_array_elements(tags) as elements;" :column))
;; there is probably a way to do this with a single query, but I couldn't codegolf it
(counted
(map 'list (lambda (tag)
(cons tag (caar (postmodern:query "SELECT count(*) from blog.post where tags ? $1" tag))))
all-tags)))
;; (("lol" . 2) ("hehe" . 2) ("ilpo" . 1) ("säätää" . 1) ("tag1" . 1) ("tag2" . 1))
(with-html
(:section
(:h* ("Tags in the system (~d)" (length counted)))
(:ul
(dolist (c counted)
(destructuring-bind (tag . count) c
;; TODO NOT IMPLEMENTED
(:li (:a :href (format nil "/blog/tags/~a" tag)
(format nil "~a (~d)" tag count))))))))))
(deftab blog/postadmin (:url "/postadmin"
:title "Manage posts"
:require-login t
:needed-abilities ("create-post" "delete-post" "edit-post"))
(setf murja.view.components.root:*inject-to-sidebar* #'tagcloud)
(let ((titles (admin-get-all-titles)))
(:div.vertical-flex-container
(dolist (title titles)
(admin-post-row title)))))