blankie
2a56107e97
fe60579a53/extensions/wikia/CreateNewWiki/CreateWikiChecks.php (L112)
Fixes https://lists.sr.ht/~cadence/breezewiki-discuss/%3C814ef2a8-2e91-dcaf-f0c1-805cc1478198%40riseup.net%3E
51 lines
2.5 KiB
Racket
51 lines
2.5 KiB
Racket
#lang racket/base
|
|
(require "syntax.rkt"
|
|
(for-syntax racket/base)
|
|
racket/string
|
|
net/url
|
|
(prefix-in host: web-server/dispatchers/dispatch-host)
|
|
(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)
|
|
"config.rkt")
|
|
|
|
(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)
|
|
(host:make
|
|
(λ (host-sym)
|
|
(if/out (config-true? 'canonical_origin)
|
|
(let* ([host-header (symbol->string host-sym)]
|
|
[splitter (string-append "." (url-host (string->url (config-get 'canonical_origin))))]
|
|
[s (string-split host-header splitter #:trim? #f)])
|
|
(if/in (and (eq? 2 (length s)) (equal? "" (cadr s)))
|
|
((hash-ref ds 'subdomain-dispatcher) (car s))))
|
|
(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 #px"^/[a-zA-Z0-9-]{3,50}/wiki/Category:.+$" (lift:make (hash-ref ds 'page-category)))
|
|
(filter:make #px"^/[a-zA-Z0-9-]{3,50}/wiki/.+$" (lift:make (hash-ref ds 'page-wiki)))
|
|
(filter:make #px"^/[a-zA-Z0-9-]{3,50}/search$" (lift:make (hash-ref ds 'page-search)))
|
|
(filter:make #px"^/[a-zA-Z0-9-]{3,50}(/(wiki(/)?)?)?$" (lift:make (hash-ref ds 'redirect-wiki-home)))
|
|
(hash-ref ds 'static-dispatcher)
|
|
(lift:make (hash-ref ds 'page-not-found)))))))
|