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