mirror of
https://gitdab.com/cadence/breezewiki.git
synced 2026-03-04 13:30:04 -05:00
fallback to no banner if extwiki unavailable
This commit is contained in:
@@ -85,46 +85,47 @@
|
||||
|
||||
(define/memoize (get-redirect-content wikiname) #:hash hash
|
||||
(define wiki (hash-ref wikis-hash wikiname #f))
|
||||
(cond
|
||||
[wiki
|
||||
(define display-name (cadr wiki))
|
||||
(define endpoint (string-append (get-api-endpoint wiki) "?action=parse&page=MediaWiki:BreezeWikiRedirect&prop=text&formatversion=2&format=json"))
|
||||
(define res (get endpoint))
|
||||
(define html (jp "/parse/text" (response-json res)))
|
||||
(define content ((query-selector (λ (t a c) (has-class? "mw-parser-output" a))
|
||||
(html->xexp html))))
|
||||
(define body (for/list ([p (in-producer (query-selector (λ (t a c) (eq? t 'p)) content) #f)]) p))
|
||||
(define table (parse-table ((query-selector (λ (t a c) (eq? t 'table)) content))))
|
||||
(define-values (links links-errors) (table->links table))
|
||||
(define-values (logo logo-errors) (table->logo table))
|
||||
(define construct-errors (append links-errors logo-errors))
|
||||
(λ (title)
|
||||
(define go
|
||||
(string-append (get-search-page wiki)
|
||||
"?"
|
||||
(params->query `(("search" . ,title)
|
||||
("go" . "Go")))))
|
||||
`(aside (@ (class "niwa__notice"))
|
||||
(h1 (@ (class "niwa__header")) ,display-name " has its own website separate from Fandom.")
|
||||
(div (@ (class "niwa__cols"))
|
||||
(div (@ (class "niwa__left"))
|
||||
(a (@ (class "niwa__go") (href ,go)) "Read " ,title " on " ,display-name " →")
|
||||
,@body
|
||||
(p "This external wiki is a helpful alternative to Fandom. You should "
|
||||
(a (@ (href ,go)) "check it out now!")))
|
||||
,(if logo
|
||||
`(div (@ (class "niwa__right"))
|
||||
(img (@ (class "niwa__logo") (src ,logo))))
|
||||
""))
|
||||
,(if (pair? links)
|
||||
`(p (@ (class "niwa__feedback"))
|
||||
,@(add-between links " / "))
|
||||
"")
|
||||
,(if (pair? construct-errors)
|
||||
`(ul
|
||||
,@(for/list ([error construct-errors])
|
||||
`(li ,error)))
|
||||
"")))]
|
||||
[#t #f]))
|
||||
(with-handlers ([exn:fail:http-easy:timeout? (λ (e) #f)])
|
||||
(cond
|
||||
[wiki
|
||||
(define display-name (cadr wiki))
|
||||
(define endpoint (string-append (get-api-endpoint wiki) "?action=parse&page=MediaWiki:BreezeWikiRedirect&prop=text&formatversion=2&format=json"))
|
||||
(define res (get endpoint))
|
||||
(define html (jp "/parse/text" (response-json res)))
|
||||
(define content ((query-selector (λ (t a c) (has-class? "mw-parser-output" a))
|
||||
(html->xexp html))))
|
||||
(define body (for/list ([p (in-producer (query-selector (λ (t a c) (eq? t 'p)) content) #f)]) p))
|
||||
(define table (parse-table ((query-selector (λ (t a c) (eq? t 'table)) content))))
|
||||
(define-values (links links-errors) (table->links table))
|
||||
(define-values (logo logo-errors) (table->logo table))
|
||||
(define construct-errors (append links-errors logo-errors))
|
||||
(λ (title)
|
||||
(define go
|
||||
(string-append (get-search-page wiki)
|
||||
"?"
|
||||
(params->query `(("search" . ,title)
|
||||
("go" . "Go")))))
|
||||
`(aside (@ (class "niwa__notice"))
|
||||
(h1 (@ (class "niwa__header")) ,display-name " has its own website separate from Fandom.")
|
||||
(div (@ (class "niwa__cols"))
|
||||
(div (@ (class "niwa__left"))
|
||||
(a (@ (class "niwa__go") (href ,go)) "Read " ,title " on " ,display-name " →")
|
||||
,@body
|
||||
(p "This external wiki is a helpful alternative to Fandom. You should "
|
||||
(a (@ (href ,go)) "check it out now!")))
|
||||
,(if logo
|
||||
`(div (@ (class "niwa__right"))
|
||||
(img (@ (class "niwa__logo") (src ,logo))))
|
||||
""))
|
||||
,(if (pair? links)
|
||||
`(p (@ (class "niwa__feedback"))
|
||||
,@(add-between links " / "))
|
||||
"")
|
||||
,(if (pair? construct-errors)
|
||||
`(ul
|
||||
,@(for/list ([error construct-errors])
|
||||
`(li ,error)))
|
||||
"")))]
|
||||
[#t #f])))
|
||||
(module+ test
|
||||
(check-not-false ((get-redirect-content "gallowmere") "MediEvil Wiki")))
|
||||
|
||||
Reference in New Issue
Block a user