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

View File

@ -40,7 +40,7 @@
(input (@ (name "wikiname") (class "paired__input") (type "text") (placeholder "pokemon") (required)))) (input (@ (name "wikiname") (class "paired__input") (type "text") (placeholder "pokemon") (required))))
(label (@ (class "paired__label")) (label (@ (class "paired__label"))
"Search query" "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")) (button "Search"))
(h2 "Example pages") (h2 "Example pages")
(ul (ul