commit d1f43a88b1dfe545e705f5add16cfd81367439fa
parent d883d20c3ca6adb1cb272985b10efe64c4cb1a46
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 29 Jul 2025 22:41:56 +0100
put topics in sidebar
Diffstat:
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/main.fnl b/main.fnl
@@ -124,6 +124,7 @@
(fn sidebar [site stream]
(let [s { :write #(stream:write_chunk $2) }
+ topics (site:topics)
ladder (all-months site)]
(stream:write_chunk "<aside>
<div> <p>
@@ -132,14 +133,26 @@ Computer programmer, inline skater, cyclist, motorcyclist: I can't keep
it separate and so neither does this blog.
<p> Shorter, swifter, and less well-formed opinions are also available
in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a>
-</div>
-<h2>The Archive</h2>
-")
- (to-html (doto ladder (table.insert 1 :ul)) s)
+</div>")
+ (to-html
+ [:div
+ [:h2 "Buzzwords"]
+ (doto
+ (icollect [_ [count topic] (pairs topics)]
+ [[:span {:class "topic"}]
+ [[:a {:href (.. "/topic/" topic) }]
+ topic]])
+ (table.insert 1 :div))]
+ s)
+ (to-html
+ [:div
+ [:h2 "The Archive"]
+ (doto ladder (table.insert 1 :ul))]
+ s)
(stream:write_chunk "</ul></aside>")))
-(define-tests :sidebar
- (print (view (all-months post-index))))
+;; (define-tests :sidebar
+;; (print (view (all-months post-index))))
(fn translate-markdown [md]
;; lcmark/cmark doesn't have any extension points that allow us
diff --git a/site.fnl b/site.fnl
@@ -159,6 +159,16 @@
posts)))
+(fn topics [posts]
+ (let [counts {}]
+ (each [_ post (pairs posts)]
+ (each [_ t (pairs post.topics)]
+ (tset counts t (case (. counts t) n (+ n 1) nil 1))))
+ (doto
+ (icollect [topic count (pairs counts)]
+ [count topic])
+ (table.sort (fn [a b] (> (. a 1) (. b 1)))))))
+
(fn for-pathname [path]
(let [posts (index-posts path)]
@@ -168,6 +178,7 @@
:path path
:static-file (fn [_ name]
(static-path-if-safe path name))
+ :topics #(topics posts)
}))
(define-tests :static-path