cripslock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 2e2a7db88979a66da66d264d3b17822dcddaf2cf
parent 9e004945385859ce2ea61eccfd1b692526c49429
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 22 Jul 2025 20:16:48 +0100

add post sidebar

Diffstat:
Mmain.fnl | 40+++++++++++++++++++++++++++++++++++++---
Mtextile.fnl | 2++
2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -110,9 +110,42 @@ (fn post-footer [post stream] (stream:write_chunk - "<aside>hey</aside> -<footer><div>Powered by <a href=\"https://gti.telent.net/dan/cripslock\">cripslock</a>. Copyright &copy; 2001-2025 Daniel Barlow</div></footer></body></html>")) - + "<footer><div>Powered by <a href=\"https://gti.telent.net/dan/cripslock\">cripslock</a>. Copyright &copy; 2001-2025 Daniel Barlow</div></footer></body></html>")) + +(fn all-months [site] + (let [h + (accumulate [months {} + (slug post) (pairs (site:search))] + (let [{ : year : month } (os.date "*t" post.date)] + (tset months year + (doto + (or (. months year) {}) + (tset month month))) + months)) + years (doto (icollect [y _ (pairs h)] y) (table.sort #(> $1 $2)))] + (icollect [_ y (ipairs years)] + (let [ms (. h y) + links (fcollect [i 1 12 &into [:li [:b y]]] + (case (. ms i) + m [:span " " [[:a {:href (string.format "/%d/%d/" y m)}] + m ]])) + ] + links)))) + + + +(fn sidebar [site stream] + (let [s { :write #(stream:write_chunk $2) } + ladder (all-months site)] + (print (view ladder)) + (stream:write_chunk "<aside><ul>") + (textile.to-html s (doto ladder (table.insert 1 :ul))) + (stream:write_chunk "</ul></aside>"))) + +(define-tests :sidebar + (print (view (all-months post-index)))) + + (fn dispatch [route stream] (let [s { :write #(stream:write_chunk $2) } ] (case route.command @@ -131,6 +164,7 @@ (stream:write_chunk (lcmark.convert (f:read "*a") "html" { :yaml_parser #($1) })) ))) + (sidebar post-index stream) (post-footer post stream) (stream:write_chunk "" true)) :sendfile diff --git a/textile.fnl b/textile.fnl @@ -280,6 +280,8 @@ (fn to-html [out-stream el] (if (= (type el) :string) (out-stream:write el) + (= (type el) :number) + (out-stream:write (tostring el)) (let [[tag & content] el (name attrstring) (case tag