diff --git a/breezewiki.rkt b/breezewiki.rkt index ac60e1f5..0421e122 100644 --- a/breezewiki.rkt +++ b/breezewiki.rkt @@ -1,7 +1,10 @@ #lang racket/base (require web-server/servlet-dispatch + (prefix-in pathprocedure: web-server/dispatchers/dispatch-pathprocedure) + (prefix-in sequencer: web-server/dispatchers/dispatch-sequencer) + (prefix-in lift: web-server/dispatchers/dispatch-lift) + (prefix-in filter: web-server/dispatchers/dispatch-filter) "src/config.rkt" - "src/dispatcher-tree.rkt" "src/reloadable.rkt") (define-syntax-rule (require-reloadable filename varname) @@ -17,6 +20,8 @@ (require-reloadable "src/page-static.rkt" static-dispatcher) (require-reloadable "src/page-wiki.rkt" page-wiki) +(when (not (config-true? 'debug)) + (set-reload-poll-interval! #f)) (reload!) (define ch (make-channel)) @@ -26,14 +31,13 @@ #:port (string->number (config-get 'port)) (λ (quit) (channel-put ch (lambda () (semaphore-post quit))) - (dispatcher-tree - ; order of these does not matter - page-category - page-home - page-not-found - page-proxy - page-search - page-wiki - static-dispatcher)))) + (sequencer:make + (pathprocedure:make "/" page-home) + (pathprocedure:make "/proxy" page-proxy) + (filter:make #rx"^/[a-z-]+/wiki/Category:.+$" (lift:make page-category)) + (filter:make #rx"^/[a-z-]+/wiki/.+$" (lift:make page-wiki)) + (filter:make #rx"^/[a-z-]+/search$" (lift:make page-search)) + static-dispatcher + (lift:make page-not-found))))) (define server-t (thread start)) (define quit (channel-get ch)) diff --git a/dist.rkt b/dist.rkt index 289f9bd3..9e190efd 100644 --- a/dist.rkt +++ b/dist.rkt @@ -1,7 +1,11 @@ #lang racket/base (require web-server/servlet-dispatch + (prefix-in pathprocedure: web-server/dispatchers/dispatch-pathprocedure) + (prefix-in sequencer: web-server/dispatchers/dispatch-sequencer) + (prefix-in lift: web-server/dispatchers/dispatch-lift) + (prefix-in filter: web-server/dispatchers/dispatch-filter) "src/config.rkt" - "src/dispatcher-tree.rkt") + "src/reloadable.rkt") (require (only-in "src/page-category.rkt" page-category)) (require (only-in "src/page-home.rkt" page-home)) @@ -15,12 +19,11 @@ #:listen-ip (if (config-true? 'debug) "127.0.0.1" #f) #:port (string->number (config-get 'port)) (λ (quit) - (dispatcher-tree - ; order of these does not matter - page-category - page-home - page-not-found - page-proxy - page-search - page-wiki - static-dispatcher))) + (sequencer:make + (pathprocedure:make "/" page-home) + (pathprocedure:make "/proxy" page-proxy) + (filter:make #rx"^/[a-z-]+/wiki/Category:.+$" (lift:make page-category)) + (filter:make #rx"^/[a-z-]+/wiki/.+$" (lift:make page-wiki)) + (filter:make #rx"^/[a-z-]+/search$" (lift:make page-search)) + static-dispatcher + (lift:make page-not-found)))) diff --git a/src/application-globals.rkt b/src/application-globals.rkt index f7d9d67d..49ea4366 100644 --- a/src/application-globals.rkt +++ b/src/application-globals.rkt @@ -26,7 +26,7 @@ `(html (head (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) - (title ,(format "~a | ~a" title (config-get 'application_name))) + (title ,(format "~a | ~a" title (config-get 'application-name))) (style ":root { --theme-page-background-color: #dfdfe0 }") ; fallback in case styles don't load fast enough ,@(map (λ (url) `(link (@ (rel "stylesheet") (type "text/css") (href ,url)))) @@ -53,22 +53,22 @@ (img (@ (class "my-logo") (src "/static/breezewiki.svg")))) (p (a (@ (href "https://gitdab.com/cadence/breezewiki")) - ,(format "~a source code" (config-get 'application_name)))) + ,(format "~a source code" (config-get 'application-name)))) (p (a (@ (href "https://lists.sr.ht/~cadence/breezewiki-discuss")) "Discussions / Bug reports / Feature requests")) - ,(if (config-get 'instance_is_official) - `(p ,(format "This instance is run by the ~a developer, " (config-get 'application_name)) + ,(if (config-get 'instance-is-official) + `(p ,(format "This instance is run by the ~a developer, " (config-get 'application-name)) (a (@ (href "https://cadence.moe/contact")) "Cadence.")) `(p - ,(format "This unofficial instance is based off the ~a source code, but is not controlled by the code developer." (config-get 'application_name))))) + ,(format "This unofficial instance is based off the ~a source code, but is not controlled by the code developer." (config-get 'application-name))))) (div (p "This page displays proxied content from " (a (@ (href ,source-url) (rel "noreferrer")) ,source-url) ". Text content is available under the Creative Commons Attribution-Share Alike License 3.0 (Unported), " (a (@ (href "https://www.fandom.com/licensing")) "see license info.") " Media files may have different copying restrictions.") - (p ,(format "Fandom is a trademark of Fandom, Inc. ~a is not affiliated with Fandom." (config-get 'application_name)))))))))))) + (p ,(format "Fandom is a trademark of Fandom, Inc. ~a is not affiliated with Fandom." (config-get 'application-name)))))))))))) (module+ test (check-not-false (xexp->html (generate-wiki-page "" "test" "test" '(template))))) diff --git a/src/config.rkt b/src/config.rkt index 38433f95..8e785ec0 100644 --- a/src/config.rkt +++ b/src/config.rkt @@ -16,11 +16,10 @@ (hash-ref config key)) (define default-config - '((application_name . "BreezeWiki") - (canonical_origin . "") + '((port . "10416") (debug . "false") - (instance_is_official . "false") ; please don't turn this on, or you will make me very upset - (port . "10416"))) + (instance-is-official . "false") ; please don't turn this on, or you will make me very upset + (application-name . "BreezeWiki"))) (define config (make-hasheq diff --git a/src/dispatcher-tree.rkt b/src/dispatcher-tree.rkt deleted file mode 100644 index 626ee093..00000000 --- a/src/dispatcher-tree.rkt +++ /dev/null @@ -1,36 +0,0 @@ -#lang racket/base -(require (for-syntax racket/base) - (prefix-in pathprocedure: web-server/dispatchers/dispatch-pathprocedure) - (prefix-in sequencer: web-server/dispatchers/dispatch-sequencer) - (prefix-in lift: web-server/dispatchers/dispatch-lift) - (prefix-in filter: web-server/dispatchers/dispatch-filter)) - -(provide - ; syntax to make the hashmap from names - dispatcher-tree - ; procedure to make the tree from the hashmap - make-dispatcher-tree) - -; make a hashmap out of the provided names and call make-dispatcher-tree with it -(define-syntax (dispatcher-tree stx) - ; the arguments, which are names of dispatcher variables - (define names (cdr (syntax->list stx))) - ; map each name to syntax of a '(name . ,name) - (define alist (map (λ (xe) ; xe is the syntax of a name - ; return instead syntax of a cons cell - (datum->syntax stx `(cons ',xe ,xe))) - names)) - ; make syntax to make the hash - (define ds (datum->syntax stx `(make-hasheq (list ,@alist)))) - ; don't forget that I'm returning *code* - return a call to the function - (datum->syntax stx `(make-dispatcher-tree ,ds))) - -(define (make-dispatcher-tree ds) - (sequencer:make - (pathprocedure:make "/" (hash-ref ds 'page-home)) - (pathprocedure:make "/proxy" (hash-ref ds 'page-proxy)) - (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))) - (hash-ref ds 'static-dispatcher) - (lift:make (hash-ref ds 'page-not-found)))) diff --git a/src/page-category.rkt b/src/page-category.rkt index bfc689fa..83f0f030 100644 --- a/src/page-category.rkt +++ b/src/page-category.rkt @@ -59,7 +59,7 @@ (define data (easy:response-json dest-res)) (define body (generate-results-page dest-url wikiname prefixed-category data)) - (when (config-true? 'debug) + (when (config-get 'debug) ; used for its side effects ; convert to string with error checking, error will be raised if xexp is invalid (xexp->html body)) diff --git a/src/page-home.rkt b/src/page-home.rkt index 102ab687..4a87a1b1 100644 --- a/src/page-home.rkt +++ b/src/page-home.rkt @@ -56,20 +56,20 @@ (footer (@ (class "custom-footer")) (div (@ (class "internal-footer")) (img (@ (class "my-logo") (src "/static/breezewiki.svg"))) - ,(if (config-get 'instance_is_official) + ,(if (config-get 'instance-is-official) `(div - (p ,(format "This instance is run by the ~a developer, " (config-get 'application_name)) + (p ,(format "This instance is run by the ~a developer, " (config-get 'application-name)) (a (@ (href "https://cadence.moe/contact")) "Cadence.")) (p "Hosting generously provided by " (a (@ (href "http://alphamethyl.barr0w.net/")) "alphamethyl."))) `(p - ,(format "This unofficial instance is based off the ~a source code, but is not controlled by the code developer." (config-get 'application_name)))) + ,(format "This unofficial instance is based off the ~a source code, but is not controlled by the code developer." (config-get 'application-name)))) (p "Text content on wikis run by Fandom is available under the Creative Commons Attribution-Share Alike License 3.0 (Unported), " (a (@ (href "https://www.fandom.com/licensing")) "see license info.") " Media files and official Fandom documents have different copying restrictions.") - (p ,(format "Fandom is a trademark of Fandom, Inc. ~a is not affiliated with Fandom." (config-get 'application_name))))))))))) + (p ,(format "Fandom is a trademark of Fandom, Inc. ~a is not affiliated with Fandom." (config-get 'application-name))))))))))) (module+ test (check-not-false (xexp->html body)))