commit ce4a3c48fb6e6b7907f97f064b1eccbb5b4d8a17
parent c42bcc14efcb938904039b5d9fc0eb6f137c1453
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 30 Jul 2025 22:44:09 +0100
skip topics in search results
Diffstat:
| M | main.fnl | | | 16 | +++++++++------- |
| M | site.fnl | | | 42 | +++++++++++++++++++++++++----------------- |
2 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/main.fnl b/main.fnl
@@ -127,15 +127,17 @@
(fn sidebar [site stream]
(let [s (cq-stream stream)
- topics (site:topics)
+ topics (site:weighted-topics)
ladder (all-months site)]
(stream:write_chunk "<aside>
-<div> <p>
-There are many Daniel Barlows on the internet, but this one's me.
-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> <p> There are many more Daniel Barlows on the internet than
+there were when I started writing this, This one is a computer
+programmer, inline skater, cyclist, motorcyclist, occasional human
+being.
+
+<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>")
(to-html
[:div
diff --git a/site.fnl b/site.fnl
@@ -128,18 +128,35 @@
fullpath (realpath (.. basedir name))]
(and fullpath (string.find fullpath prefix 1 true) fullpath)))
+(fn topics [posts]
+ (let [counts {}]
+ (each [_ post (pairs posts)]
+ (each [_ t (pairs post.topics)]
+ (tset counts t t)))
+ counts))
+(fn weighted-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 search-posts [posts { : filter : order : offset : limit &as opts }]
- (let [posts
+ (let [topics (topics posts)
+ posts
(icollect [_ post (pairs posts)]
(when
- (case filter
- { : newer : older }
- (and post.date (> post.date newer) (< post.date older))
- { : topic }
- (. post.topics topic)
- _ true)
+ (and (not (. topics post.slug))
+ (case filter
+ { : newer : older }
+ (and post.date (> post.date newer) (< post.date older))
+ { : topic }
+ (. post.topics topic)
+ _ true))
post))]
(if order
(let [(field dir) ((pairs order) order)
@@ -159,16 +176,6 @@
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)]
@@ -179,6 +186,7 @@
:static-file (fn [_ name]
(static-path-if-safe path name))
:topics #(topics posts)
+ :weighted-topics #(weighted-topics posts)
}))
(define-tests :static-path