Add global search on home page

This commit is contained in:
Cadence Ember 2022-09-17 22:36:04 +12:00
parent 82978e7c13
commit 711a8225fb
Signed by untrusted user: cadence
GPG key ID: BC1C2C61CF521B17
5 changed files with 42 additions and 3 deletions

View file

@ -10,6 +10,7 @@
(make-reloadable-entry-point (quote varname) filename))))
(require-reloadable "src/page-category.rkt" page-category)
(require-reloadable "src/page-global-search.rkt" page-global-search)
(require-reloadable "src/page-home.rkt" page-home)
(require-reloadable "src/page-not-found.rkt" page-not-found)
(require-reloadable "src/page-proxy.rkt" page-proxy)
@ -31,6 +32,7 @@
(dispatcher-tree
; order of these does not matter
page-category
page-global-search
page-home
page-not-found
page-proxy

View file

@ -4,6 +4,7 @@
"src/dispatcher-tree.rkt")
(require (only-in "src/page-category.rkt" page-category))
(require (only-in "src/page-global-search.rkt" page-global-search))
(require (only-in "src/page-home.rkt" page-home))
(require (only-in "src/page-not-found.rkt" page-not-found))
(require (only-in "src/page-proxy.rkt" page-proxy))
@ -20,6 +21,7 @@
(dispatcher-tree
; order of these does not matter
page-category
page-global-search
page-home
page-not-found
page-proxy

View file

@ -42,6 +42,7 @@
(sequencer:make
(pathprocedure:make "/" (hash-ref ds 'page-home))
(pathprocedure:make "/proxy" (hash-ref ds 'page-proxy))
(pathprocedure:make "/search" (hash-ref ds 'page-global-search))
(filter:make #rx"^/[a-z-]+/wiki/Category:.+$" (lift:make (hash-ref ds 'page-category)))
(filter:make #rx"^/[a-z-]+/wiki/.+$" (lift:make (hash-ref ds 'page-wiki)))
(filter:make #rx"^/[a-z-]+/search$" (lift:make (hash-ref ds 'page-search)))

View file

@ -0,0 +1,25 @@
#lang racket/base
(require racket/dict
; web server libs
net/url
web-server/http
"application-globals.rkt"
"url-utils.rkt"
"xexpr-utils.rkt")
(provide
page-global-search)
(define (page-global-search req)
(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))
(response/output
#:code 400
#:mime-type "text/plain"
(λ (out)
(displayln "Requires wikiname and q parameters." out)))
(generate-redirect (format "/~a/search?~a"
wikiname
(params->query `(("q" . ,q))))))))

View file

@ -32,6 +32,15 @@
"breezewiki.com")))
(p "If you'd like to be automatically sent to BreezeWiki every time in the future, "
(a (@ (href "https://docs.breezewiki.com/Automatic_Redirection.html")) "check out the tutorial in the manual."))
(h2 "Find a page")
(form (@ (action "/search"))
(label (@ (class "paired__label"))
"Wiki name"
(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))))
(button "Search"))
(h2 "Example pages")
(ul
,@(map (λ (x)