From 7a8a1cd40fed3b2a05730df37b6e81f8028bf05c Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 10 Oct 2022 22:52:35 +1300 Subject: [PATCH] Remove noscript versions of images Script versions are likely better quality, and BreezeWiki makes them viewable without requiring scripts anyway. --- src/page-wiki.rkt | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/page-wiki.rkt b/src/page-wiki.rkt index effa40a..07f2f81 100644 --- a/src/page-wiki.rkt +++ b/src/page-wiki.rkt @@ -51,6 +51,17 @@ (p "Another page link: " (a (@ (data-test-wikilink) (href "https://test.fandom.com/wiki/Another_Page") (title "Another Page")) "Another Page")))) + (figure (@ (class "thumb tnone")) + (a (@ (href "https://static.wikia.nocookie.net/nice-image.png") (class "image")) + (img (@ (src "data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D") + (data-src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") + (class "thumbimage lazyload")))) + (noscript + (a (@ (href "https://static.wikia.nocookie.net/nice-image.png") (class "image")) + (img (@ (src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") + (data-src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") + (class "thumbimage"))))) + (figcaption "Test figure!")) (iframe (@ (src "https://example.com/iframe-src"))))))) (define (preprocess-html-wiki html) @@ -108,6 +119,15 @@ `(a ((class "iframe-alternative") (href ,src)) (,(format "Embedded media: ~a" src)))] + ; remove noscript versions of images because they are likely lower quality than the script versions + [(and (eq? element-type 'noscript) + (match children + ; either the noscript has a.image as a first child... + [(list (list 'a (list '@ a-att ...) _)) (has-class? "image" a-att)] + ; or the noscript has img as a first child + [(list (list 'img _)) #t] + [_ #f])) + return-no-element] [#t (list element-type ;; attributes @@ -233,7 +253,9 @@ ((query-selector (λ (t a c) (and (eq? t 'a) (has-class? "image-thumbnail" a))) transformed)))) - "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fnice-image.png")) + "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fnice-image.png") + ; check that noscript images are removed + (check-equal? ((query-selector (λ (t a c) (eq? t 'noscript)) transformed)) #f)) (define (page-wiki req) (define wikiname (path/param-path (first (url-path (request-uri req)))))