cripslock

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

commit e1b54c0e06db04f8c6dc19888a234ef5d52e6de6
parent e8fa90102f8babd2a1561617c805393412cf97cf
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 31 Aug 2026 21:36:32 +0100

add search form

Diffstat:
Mmain.fnl | 43+++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+), 0 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -34,6 +34,11 @@ path [ :static { : path } ]) + #(let [{ : path : query } (url.parse $2)] + (if (= path "/search") + (let [terms query.terms] + [ :search {:terms terms }]))) + #(let [{ : path : query } (url.parse $2) { : order : direction } query direction (. { :ascending :ascending @@ -172,6 +177,14 @@ 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 "Search"] + [:p "Google has given up on me (it's mutual)"] + [[:form {:method :get :action "/search" }] + [[:input {:name :terms :type :text}]] + [[:input {:name :go :value "Search" :type :submit}]]]] + s) (to-html (topics-html topics) s) (to-html [:div @@ -283,6 +296,34 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a> (page-footer stream) (stream:write_chunk "" true))) +(fn send-search-page [stream collection terms] + (let [order { :similarity :descending } + results (collection:search {:filter {:terms terms} + : order }) + s (stream-from-cq-stream stream)] + (server.headers stream { }) + (page-header stream (.. "Searched for " terms)) + + (to-html + [:div + [:h2 "Results"] + [[:div {:style "text-align: right"}] + "sort by " + [:span [[:a {:href "?order=date&direction=descending"}] "date"]] + " | " + [:span [[:a {:href "?order=title&direction=ascending"}] "title"]]] + (prepend :ul + (icollect [_ p (ipairs results)] + [:li + [[:a { :href p.url-path}] p.title] + ", " + (os.date "%d %b %Y" p.date) + ]))] + s) + (sidebar stream collection) + (page-footer stream) + (stream:write_chunk "" true))) + (fn send-rss [stream collection] (let [posts (collection:search @@ -320,6 +361,8 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a> (stream:write_body_from_file f))) [:home { : limit }] (send-home-page stream collection) + [:search { : terms }] + (send-search-page stream collection terms) [:topic { : slug &as p }] (send-topic-page stream collection slug p.order)