forked from cadence/breezewiki
raco fmt
This commit is contained in:
parent
1a996e7c89
commit
51bf087b30
1 changed files with 66 additions and 84 deletions
|
@ -20,8 +20,7 @@
|
|||
"url-utils.rkt"
|
||||
"xexpr-utils.rkt")
|
||||
|
||||
(provide
|
||||
page-file)
|
||||
(provide page-file)
|
||||
|
||||
;(module+ test
|
||||
; (require rackunit)
|
||||
|
@ -36,16 +35,13 @@
|
|||
(define (get-media-html url content-type)
|
||||
(cond
|
||||
[(eq? content-type #f) `""]
|
||||
[(regexp-match? #rx"(?i:^image/)" content-type)
|
||||
`(img (@ (src ,url)))]
|
||||
[(regexp-match? #rx"(?i:^image/)" content-type) `(img (@ (src ,url)))]
|
||||
[(regexp-match? #rx"(?i:^audio/|^application/ogg(;|$))" content-type)
|
||||
`(audio (@ (src ,url) (controls)))]
|
||||
[(regexp-match? #rx"(?i:^video/)" content-type)
|
||||
`(video (@ (src ,url) (controls)))]
|
||||
[(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,url) (controls)))]
|
||||
[else `""]))
|
||||
|
||||
(define (generate-results-page
|
||||
#:source-url source-url
|
||||
(define (generate-results-page #:source-url source-url
|
||||
#:wikiname wikiname
|
||||
#:title title
|
||||
#:media-detail media-detail
|
||||
|
@ -59,9 +55,8 @@
|
|||
(define smaller-article-list (jp "/smallerArticleList" media-detail))
|
||||
(define article-list-is-smaller (jp "/articleListIsSmaller" media-detail))
|
||||
(define image-description (jp "/imageDescription" media-detail #f))
|
||||
(define maybe-proxied-raw-image-url (if (config-true? 'strict_proxy)
|
||||
(u-proxy-url raw-image-url)
|
||||
raw-image-url))
|
||||
(define maybe-proxied-raw-image-url
|
||||
(if (config-true? 'strict_proxy) (u-proxy-url raw-image-url) raw-image-url))
|
||||
(generate-wiki-page
|
||||
#:source-url source-url
|
||||
#:wikiname wikiname
|
||||
|
@ -71,8 +66,7 @@
|
|||
,(if (non-empty-string? video-embed-code)
|
||||
(update-tree-wiki (html->xexp (preprocess-html-wiki video-embed-code)) wikiname)
|
||||
(get-media-html image-url image-content-type))
|
||||
(p
|
||||
,(if (non-empty-string? video-embed-code)
|
||||
(p ,(if (non-empty-string? video-embed-code)
|
||||
`""
|
||||
`(span (a (@ (href ,maybe-proxied-raw-image-url)) "View original file") ". "))
|
||||
"Added by "
|
||||
|
@ -80,20 +74,13 @@
|
|||
"."
|
||||
,(if is-posted-in
|
||||
`(span " Posted in "
|
||||
,@(map
|
||||
(λ (article)
|
||||
,@(map (λ (article)
|
||||
(define page-path (jp "/title" article))
|
||||
(define title (jp "/titleText" article page-path))
|
||||
`(span
|
||||
,(if (eq? (car smaller-article-list) article)
|
||||
""
|
||||
", ")
|
||||
(a (@ (href ,(format "/~a/wiki/~a" wikiname page-path)))
|
||||
,title)))
|
||||
`(span ,(if (eq? (car smaller-article-list) article) "" ", ")
|
||||
(a (@ (href ,(format "/~a/wiki/~a" wikiname page-path))) ,title)))
|
||||
smaller-article-list)
|
||||
,(if (eq? article-list-is-smaller 1)
|
||||
"…"
|
||||
"."))
|
||||
,(if (eq? article-list-is-smaller 1) "…" "."))
|
||||
`""))
|
||||
,(if (string? image-description)
|
||||
(update-tree-wiki (html->xexp (preprocess-html-wiki image-description)) wikiname)
|
||||
|
@ -105,45 +92,40 @@
|
|||
(define origin (format "https://~a.fandom.com" wikiname))
|
||||
(define source-url (format "~a/wiki/~a" origin prefixed-title))
|
||||
|
||||
(thread-let
|
||||
([media-detail (define dest-url
|
||||
(thread-let ([media-detail
|
||||
(define dest-url
|
||||
(format "~a/wikia.php?~a"
|
||||
origin
|
||||
(params->query `(("format" . "json")
|
||||
("controller" . "Lightbox")
|
||||
(params->query `(("format" . "json") ("controller" . "Lightbox")
|
||||
("method" . "getMediaDetail")
|
||||
("fileTitle" . ,prefixed-title)))))
|
||||
(log-outgoing dest-url)
|
||||
(define dest-res (easy:get dest-url #:timeouts timeouts))
|
||||
(easy:response-json dest-res)]
|
||||
[license (license-auto wikiname)])
|
||||
|
||||
(if (not (jp "/exists" media-detail #f))
|
||||
(next-dispatcher)
|
||||
(response-handler
|
||||
(define file-title (jp "/fileTitle" media-detail ""))
|
||||
(define title (if (non-empty-string? file-title)
|
||||
(format "File:~a" file-title)
|
||||
prefixed-title))
|
||||
(define image-content-type (if (non-empty-string? (jp "/videoEmbedCode" media-detail ""))
|
||||
(define title
|
||||
(if (non-empty-string? file-title) (format "File:~a" file-title) prefixed-title))
|
||||
(define image-content-type
|
||||
(if (non-empty-string? (jp "/videoEmbedCode" media-detail ""))
|
||||
#f
|
||||
(url-content-type (jp "/imageUrl" media-detail))))
|
||||
(define body (generate-results-page
|
||||
#:source-url source-url
|
||||
(define body
|
||||
(generate-results-page #:source-url source-url
|
||||
#:wikiname wikiname
|
||||
#:title title
|
||||
#:media-detail media-detail
|
||||
#:image-content-type image-content-type
|
||||
#:license license))
|
||||
|
||||
(when (config-true? 'debug)
|
||||
; used for its side effects
|
||||
; convert to string with error checking, error will be raised if xexp is invalid
|
||||
(xexp->html body))
|
||||
(response/output
|
||||
#:code 200
|
||||
(λ (out)
|
||||
(write-html body out)))))))
|
||||
(response/output #:code 200
|
||||
(λ (out) (write-html body out)))))))
|
||||
;(module+ test
|
||||
; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")
|
||||
; (generate-results-page
|
||||
|
|
Loading…
Reference in a new issue