Allow searching for nothing on BreezeWiki homepage

This commit is contained in:
Cadence Ember 2022-11-10 23:20:09 +13:00
parent aab52bd92b
commit 02819a7459
Signed by: cadence
GPG key ID: BC1C2C61CF521B17
2 changed files with 17 additions and 10 deletions

View file

@ -4,6 +4,7 @@
net/url
web-server/http
"application-globals.rkt"
"data.rkt"
"url-utils.rkt"
"xexpr-utils.rkt")
@ -14,12 +15,18 @@
(define wikiname (dict-ref (url-query (request-uri req)) 'wikiname #f))
(define q (dict-ref (url-query (request-uri req)) 'q #f))
(response-handler
(if (not (and wikiname q))
(cond
[(not wikiname)
(response/output
#:code 400
#:mime-type "text/plain"
(λ (out)
(displayln "Requires wikiname and q parameters." out)))
(displayln "Requires wikiname and q parameters." out)))]
[(or (not q) (equal? q ""))
(define siteinfo (siteinfo-fetch wikiname))
(define dest (format "/~a/wiki/~a" wikiname (or (siteinfo^-basepage siteinfo) "Main_Page")))
(generate-redirect dest)]
[#t
(generate-redirect (format "/~a/search?~a"
wikiname
(params->query `(("q" . ,q))))))))
(params->query `(("q" . ,q)))))])))

View file

@ -40,7 +40,7 @@
(input (@ (name "wikiname") (class "paired__input") (type "text") (placeholder "pokemon") (required))))
(label (@ (class "paired__label"))
"Search query"
(input (@ (name "q") (class "paired__input") (type "text") (placeholder "Eevee") (required))))
(input (@ (name "q") (class "paired__input") (type "text") (placeholder "Eevee"))))
(button "Search"))
(h2 "Example pages")
(ul