cripslock

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

commit ec3a16d1f86170f0e29e54f0747a7ebd6b18e717
parent 44ea824d44c46e4d6ac0cfccfc22a81362859170
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 16 Sep 2026 17:59:47 +0100

support limit and offset query params for news.rss

Diffstat:
Mmain.fnl | 38+++++++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -30,11 +30,15 @@ [ #(if (= $2 "/") [ :home { :limit 5 } ]) #(if (= $2 "/refresh") [ :refresh {} ]) - #(if (= $2 "/news.rss") [ :rss { :limit 10 } ]) - #(case (string.match $2 "^/topic/([%w_-]+)/news.rss") - topic - [ :rss {:limit 10 :topic topic } ] - ) + #(if (string.match $2 "/news.rss") + (let [{: path : query} (url.parse $2) + topic (string.match path "^/topic/([%w_-]+)/")] + (and (or topic (= path "/news.rss")) + [ :rss { + :topic topic + :limit (tonumber (or query.limit 10)) + :offset (tonumber (or query.offset 0)) + }]))) #(case (string.match $2 "^/(%d+)/(%d+)/") (year month) [ :month { :year (tonumber year) :month (tonumber month) } ] @@ -98,6 +102,20 @@ (expect= (route-request :get "/topic/cripslock" route-matchers) [ :topic {:slug "cripslock" } ]) + (expect= (route-request :get "/news.rss" route-matchers) + [ :rss {:limit 10 :offset 0 }]) + (expect= (route-request :get "/news.rss?offset=42" route-matchers) + [ :rss {:limit 10 :offset 42 }]) + (expect= (route-request :get "/news.rss?limit=9&offset=42" route-matchers) + [ :rss {:limit 9 :offset 42 }]) + + (expect= (route-request :get "/topic/fish/news.rss" route-matchers) + [ :rss {:limit 10 :offset 0 :topic "fish"}]) + (expect= (route-request :get "/topic/fish//news.rss?offset=42" route-matchers) + [ :rss {:limit 10 :offset 42 :topic "fish" }]) + (expect= (route-request :get "/topic/fish////news.rss?limit=9&offset=42" route-matchers) + [ :rss {:limit 9 :offset 42 :topic "fish" }]) + (expect= (route-request :get "/topic/cripslock?order=date&direction=ascending" route-matchers) [ :topic {:slug "cripslock" :order { :date :ascending }} ]) ) @@ -362,13 +380,13 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a> (page-footer stream) (stream:write_chunk "" true))) -(fn send-rss [stream collection limit topic] +(fn send-rss [stream collection { : offset : limit : topic }] (let [posts (collection:search { :filter (and topic { : topic }) :order {:date :descending} - :offset 0 + :offset offset :limit limit })] (server.headers stream @@ -402,10 +420,8 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a> (case (collection:get slug) post (send-post-page stream collection post) nil (server.headers stream { ":status" :404 } true)) - [:rss { : limit : topic }] - (send-rss stream collection limit topic) - [:rss { : limit }] - (send-rss stream collection limit nil) + [:rss { : limit : offset : topic }] + (send-rss stream collection { : limit : offset : topic }) [:refresh _] (do (print "refreshing")