cripslock

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

commit 9f360369e1aacb9201cf2c0a57c20734b1c27ad1
parent 74fffc50ee7d14884135448a7a51320f32a8daa4
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 22 Jul 2025 22:30:20 +0100

implement date ranges in site search

Diffstat:
Mmain.fnl | 29++++++++++++++++++-----------
Msite.fnl | 19+++++++++++++++++--
2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -129,7 +129,7 @@ (fn all-months [site] (let [h (accumulate [months {} - (slug post) (pairs (site:search))] + (slug post) (pairs (site:search {}))] (let [{ : year : month } (os.date "*t" post.date)] (tset months year (doto @@ -167,6 +167,21 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (define-tests :sidebar (print (view (all-months post-index)))) +(fn search-posts [route stream] + (server.headers stream { }) + (page-header stream "Recently") + (stream:write_chunk "<p><ul>") + (each [slug post (pairs (post-index:search route))] + (stream:write_chunk + (string.format + "<li><a href=%q>%s</a></li>" + slug + (or post.title post.subject)))) + (stream:write_chunk "</ul>" ) + (sidebar post-index stream) + (page-footer stream) + (stream:write_chunk "" true )) + (fn dispatch [route stream] (let [s { :write #(stream:write_chunk $2) } ] @@ -195,16 +210,8 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (server.headers stream { :content-type (content-type-for-path route.pathname) }) (stream:write_body_from_file f)) :search - (do - (server.headers stream { }) - (stream:write_chunk "<p><ul>") - (each [slug post (pairs (post-index:search))] - (stream:write_chunk - (string.format - "<li><a href=%q>%s</a></li>" - slug - (or post.title post.subject)))) - (stream:write_chunk "</ul>" true))))) + (search-posts route stream) + ))) (fn http-handler [_ stream] (let [req-headers (assert (stream:get_headers)) diff --git a/site.fnl b/site.fnl @@ -1,7 +1,7 @@ (import-macros { : define-tests : expect : expect= } :assert) (local lfs (require :lfs)) (local { : realpath } (require :posix.stdlib)) - +(local { : view } (require :fennel)) ;; there are two date formats used in most of the extant posts: ;; "Fri Jun 29 14:17:56 2018" (emacs current-time-string) @@ -121,11 +121,26 @@ fullpath (realpath (.. basedir name))] (and fullpath (string.find fullpath prefix 1 true) fullpath))) + + +(fn search-posts [posts { : filter : order : offset : limit &as opts }] + (accumulate [out {} + slug post (pairs posts)] + (do + (when + (case filter + { : newer : older } + (and post.date (> post.date newer) (< post.date older)) + _ true) + (tset out slug post)) + out))) + + (fn for-pathname [path] (let [posts (index-posts path)] { :get #(. posts $2) - :search (fn [_] posts) + :search #(search-posts posts $2) :path path :static-file (fn [_ name] (static-path-if-safe path name))