cripslock

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

commit 81550d90fb85a5a5b88b7ba0f08bf9a668c4900d
parent 1b5e1f56fd214f0e4d6c532b8e6f9313d5057966
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 28 Jul 2025 00:24:25 +0100

extract fn send-search-results to use in /{ ... } handling

Diffstat:
Mmain.fnl | 36++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -169,19 +169,19 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (define-tests :sidebar (print (view (all-months post-index)))) +(local send-search-results #true) + (fn subst-search-result [text] (let [(ok? terms) ((fennel.parser text))] (case terms { : filter : format } - (let [results (post-index:search terms)] - (table.concat - (icollect [_ post (ipairs results)] - (string.format "* [[%s]]\n" post.slug)))) + (let [results (post-index:search terms) + s (string-stream)] + (send-search-results s format results) + (s:to-string)) _ "search syntax error"))) - - (fn translate-markdown [md] ;; lcmark/cmark doesn't have any extension points that allow us ;; to add actual new syntax so we're just going to postprocess @@ -216,17 +216,25 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (to-html [[:div {:class :continuelink}] [:div [[:a { :href post.url-path}] "... continue reading"]]] s)))))) +(set-forcibly! + send-search-results + (fn [stream format results] + (case format + :titles + (to-html + (prepend :ul + (icollect [_ p (ipairs results)] + [:li [[:a { :href p.url-path}] p.title]])) + stream + ) + _ + (each [_ p (ipairs results)] + (send-post p stream (= format :excerpts)))))) + (fn search-posts [route stream] (server.headers stream { }) (page-header stream "Recently") - (stream:write_chunk "<p><ul>") - (each [_ post (pairs (post-index:search route))] - (case route.format - :posts - (send-post post stream) - :excerpts - (send-post post stream true))) - (stream:write_chunk "</ul>" ) + (send-search-results stream route.format (post-index:search route)) (sidebar post-index stream) (page-footer stream) (stream:write_chunk "" true ))