Compare commits
4 Commits
e8fa90102f
...
6be6ac9361
| Author | SHA1 | Date | |
|---|---|---|---|
| 6be6ac9361 | |||
| cee906bb50 | |||
| e0d81ccb6f | |||
| e1b54c0e06 |
@@ -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
|
||||
@@ -158,7 +163,7 @@ img.floated { width: 40%%; float: right; clear: right; border: 1px #555 solid; b
|
||||
topic]])
|
||||
(table.insert 1 :div))]))
|
||||
|
||||
(fn sidebar [stream collection]
|
||||
(fn sidebar [stream collection terms]
|
||||
(let [s (stream-from-cq-stream stream)
|
||||
topics (collection:weighted-topics)
|
||||
ladder (all-months collection)]
|
||||
@@ -172,9 +177,17 @@ 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 {:id :search}]
|
||||
[:h2 "Search"]
|
||||
[:p "Google has given up on me (it's mutual). Search previous entries."]
|
||||
[[:form {:method :get :action "/search" }]
|
||||
[[:input {:name :terms :type :text :value (or terms "")}]]
|
||||
[[:input {:name :go :value "Search" :type :submit}]]]]
|
||||
s)
|
||||
(to-html (topics-html topics) s)
|
||||
(to-html
|
||||
[:div
|
||||
[[:div {:id :archive}]
|
||||
[:h2 "The Archive"]
|
||||
(doto ladder (table.insert 1 :ul))]
|
||||
s)
|
||||
@@ -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 terms)
|
||||
(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)
|
||||
|
||||
|
||||
@@ -279,6 +279,9 @@
|
||||
names ["20260102_Magic_DNS.md" "e0b74727-b5b3-4091-92f3-936a758b286b.md"]
|
||||
))))
|
||||
|
||||
;; which fields are we allowing to sort result on
|
||||
(local order-fields
|
||||
(collect [_ k (ipairs [:date :title :similarity])] (values k k)))
|
||||
|
||||
(fn search-posts [posts df { : filter : order : offset : limit &as opts }]
|
||||
(let [topics (topics posts)
|
||||
@@ -296,6 +299,7 @@
|
||||
post))]
|
||||
(if order
|
||||
(let [(field dir) ((pairs order) order)
|
||||
field (or (. order-fields field) :date)
|
||||
cmp (fn [a b]
|
||||
(let [aa (or (. a field) 0)
|
||||
bb (or (. b field) 0)]
|
||||
|
||||
Reference in New Issue
Block a user