commit 52ffe63fbb3aa93c2c66a0d91082a1e20bb2444f
parent b1f809915dbf0e2c7d84c63cfd693289ece6bb73
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 6 Aug 2025 17:34:35 +0100
vary font size on topics sidebar box
Diffstat:
2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/lib.fnl b/lib.fnl
@@ -11,4 +11,8 @@
:to-string #(table.concat strings)
}))
-{ : prepend : string-stream }
+(local { : view} (require :fennel))
+
+(fn trace [x] (print :trace (view x)) x)
+
+{ : prepend : string-stream : trace "%%" string.format }
diff --git a/main.fnl b/main.fnl
@@ -11,7 +11,7 @@
(local rss (require :rss))
(local { : to-html } (require :html))
-(local { : string-stream : prepend } (require :lib))
+(local { : string-stream : prepend : %% : trace } (require :lib))
(local { : view } (require :fennel))
@@ -120,6 +120,27 @@
(fn stream-from-cq-stream [stream]
{ :write #(stream:write_chunk $2 false) })
+
+(fn topics-html [topics]
+ (let [[min max]
+ (accumulate [[min max] [99999 0]
+ _ [count topic] (pairs topics)]
+ [(math.min min count) (math.max max count)])
+ scale (fn [c]
+ (+ 15
+ (math.floor (* c (/ (- 24.0 12) (- max min))))))]
+ [:div
+ [:h2 "Buzzwords"]
+ (doto
+ (icollect [_ [count topic]
+ (pairs topics)]
+ [[:span {:class "topic"}]
+ " "
+ [[:a { :style (%% "font-size: %dpx" (scale count))
+ :href (.. "/topic/" topic) }]
+ topic]])
+ (table.insert 1 :div))]))
+
(fn sidebar [site stream]
(let [s (stream-from-cq-stream stream)
topics (site:weighted-topics)
@@ -134,16 +155,7 @@ being.
well-formed opinions are also available in the Fediverse at <a
href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a>
</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 (topics-html topics) s)
(to-html
[:div
[:h2 "The Archive"]