Add global search on home page
This commit is contained in:
		
							parent
							
								
									82978e7c13
								
							
						
					
					
						commit
						711a8225fb
					
				
					 5 changed files with 42 additions and 3 deletions
				
			
		| 
						 | 
					@ -10,6 +10,7 @@
 | 
				
			||||||
     (make-reloadable-entry-point (quote varname) filename))))
 | 
					     (make-reloadable-entry-point (quote varname) filename))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(require-reloadable "src/page-category.rkt" page-category)
 | 
					(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-home.rkt" page-home)
 | 
				
			||||||
(require-reloadable "src/page-not-found.rkt" page-not-found)
 | 
					(require-reloadable "src/page-not-found.rkt" page-not-found)
 | 
				
			||||||
(require-reloadable "src/page-proxy.rkt" page-proxy)
 | 
					(require-reloadable "src/page-proxy.rkt" page-proxy)
 | 
				
			||||||
| 
						 | 
					@ -31,6 +32,7 @@
 | 
				
			||||||
     (dispatcher-tree
 | 
					     (dispatcher-tree
 | 
				
			||||||
      ; order of these does not matter
 | 
					      ; order of these does not matter
 | 
				
			||||||
      page-category
 | 
					      page-category
 | 
				
			||||||
 | 
					      page-global-search
 | 
				
			||||||
      page-home
 | 
					      page-home
 | 
				
			||||||
      page-not-found
 | 
					      page-not-found
 | 
				
			||||||
      page-proxy
 | 
					      page-proxy
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								dist.rkt
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								dist.rkt
									
										
									
									
									
								
							| 
						 | 
					@ -4,6 +4,7 @@
 | 
				
			||||||
         "src/dispatcher-tree.rkt")
 | 
					         "src/dispatcher-tree.rkt")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(require (only-in "src/page-category.rkt" page-category))
 | 
					(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-home.rkt" page-home))
 | 
				
			||||||
(require (only-in "src/page-not-found.rkt" page-not-found))
 | 
					(require (only-in "src/page-not-found.rkt" page-not-found))
 | 
				
			||||||
(require (only-in "src/page-proxy.rkt" page-proxy))
 | 
					(require (only-in "src/page-proxy.rkt" page-proxy))
 | 
				
			||||||
| 
						 | 
					@ -20,6 +21,7 @@
 | 
				
			||||||
   (dispatcher-tree
 | 
					   (dispatcher-tree
 | 
				
			||||||
    ; order of these does not matter
 | 
					    ; order of these does not matter
 | 
				
			||||||
    page-category
 | 
					    page-category
 | 
				
			||||||
 | 
					    page-global-search
 | 
				
			||||||
    page-home
 | 
					    page-home
 | 
				
			||||||
    page-not-found
 | 
					    page-not-found
 | 
				
			||||||
    page-proxy
 | 
					    page-proxy
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,6 +42,7 @@
 | 
				
			||||||
             (sequencer:make
 | 
					             (sequencer:make
 | 
				
			||||||
              (pathprocedure:make "/" (hash-ref ds 'page-home))
 | 
					              (pathprocedure:make "/" (hash-ref ds 'page-home))
 | 
				
			||||||
              (pathprocedure:make "/proxy" (hash-ref ds 'page-proxy))
 | 
					              (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/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-]+/wiki/.+$" (lift:make (hash-ref ds 'page-wiki)))
 | 
				
			||||||
              (filter:make #rx"^/[a-z-]+/search$" (lift:make (hash-ref ds 'page-search)))
 | 
					              (filter:make #rx"^/[a-z-]+/search$" (lift:make (hash-ref ds 'page-search)))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										25
									
								
								src/page-global-search.rkt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/page-global-search.rkt
									
										
									
									
									
										Normal 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))))))))
 | 
				
			||||||
| 
						 | 
					@ -27,11 +27,20 @@
 | 
				
			||||||
    (p "It removes ads, videos, and suggested content, leaving you with a clean page that doesn't slow down your device or use up your data.")
 | 
					    (p "It removes ads, videos, and suggested content, leaving you with a clean page that doesn't slow down your device or use up your data.")
 | 
				
			||||||
    (p "BreezeWiki can also be called an \"alternative frontend for Fandom\".")
 | 
					    (p "BreezeWiki can also be called an \"alternative frontend for Fandom\".")
 | 
				
			||||||
    (p ,(format "To use BreezeWiki, just replace \"fandom.com\" with \"~a\", and you'll instantly be teleported to a better world."
 | 
					    (p ,(format "To use BreezeWiki, just replace \"fandom.com\" with \"~a\", and you'll instantly be teleported to a better world."
 | 
				
			||||||
               (if (config-true? 'canonical_origin)
 | 
					                (if (config-true? 'canonical_origin)
 | 
				
			||||||
                   (url-host (string->url (config-get 'canonical_origin)))
 | 
					                    (url-host (string->url (config-get 'canonical_origin)))
 | 
				
			||||||
                   "breezewiki.com")))
 | 
					                    "breezewiki.com")))
 | 
				
			||||||
    (p "If you'd like to be automatically sent to BreezeWiki every time in the future, "
 | 
					    (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."))
 | 
					       (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")
 | 
					    (h2 "Example pages")
 | 
				
			||||||
    (ul
 | 
					    (ul
 | 
				
			||||||
     ,@(map (λ (x)
 | 
					     ,@(map (λ (x)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue