cripslock

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

commit d041e9a4e7d4a58abcfea323b331096f9d48fc56
parent 3a26ea964bbf3d6620632101f179e085f5e1d2b0
Author: Daniel Barlow <dan@telent.net>
Date:   Sat,  9 Aug 2025 13:28:58 +0100

parse query params in topic handler

Diffstat:
Mmain.fnl | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -2,6 +2,7 @@ (local lfs (require :lfs)) (local lcmark (require :lcmark)) (local cqueues (require :cqueues)) +(local url (require :net.url)) (local server (require :server)) (local textile (require :textile)) @@ -33,8 +34,12 @@ path [ :static { : path } ]) - #(case (string.match $2 "^/topic/([%w_-]+)$") - slug [ :topic { : slug }]) + #(let [{ : path : query } (url.parse $2) + (field dir) (if query.order + (string.match query.order "(%g-)_(%g+)")) + order (and field dir (doto {} (tset field dir)))] + (case (string.match path "^/topic/([%w_-]+)$") + slug [ :topic { : slug : order } ])) #(case (string.match $2 "^/([%w_]+)$") slug [ :show { : slug }]) @@ -61,6 +66,12 @@ (expect= (route-request :get "/topic/cripslock" handlers) [ :topic {:slug "cripslock" } ]) + + (expect= (route-request :get "/topic/cripslock" handlers) + [ :topic {:slug "cripslock" } ]) + + (expect= (route-request :get "/topic/cripslock?order=date_ascending" handlers) + [ :topic {:slug "cripslock" :order { :date :ascending }} ]) )