From aab52bd92bfc46130c3b6d2802c7d0d423d1ac70 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sat, 5 Nov 2022 23:40:05 +1300 Subject: [PATCH] Use standards mode on all pages --- src/application-globals.rkt | 82 +++++++++++++++++++------------------ src/page-home.rkt | 40 +++++++++--------- src/page-wiki.rkt | 17 ++++---- src/static-data.rkt | 6 ++- src/xexpr-utils.rkt | 38 +++++++++++------ 5 files changed, 101 insertions(+), 82 deletions(-) diff --git a/src/application-globals.rkt b/src/application-globals.rkt index 5f290cb..595e9dd 100644 --- a/src/application-globals.rkt +++ b/src/application-globals.rkt @@ -116,46 +116,48 @@ ; combine the above entries into a single request for potentially extra speed - fandom.com doesn't even do this! "~a/wikia.php?controller=ThemeApi&method=themeVariables" "~a/load.php?lang=en&modules=skin.fandomdesktop.styles%7Cext.fandom.PortableInfoboxFandomDesktop.css%7Cext.fandom.GlobalComponents.CommunityHeaderBackground.css%7Cext.gadget.site-styles%2Csound-styles%7Csite.styles&only=styles&skin=fandomdesktop"))) - `(html - (head - (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) - (title ,(format "~a | ~a+~a" - title - (regexp-replace #rx" ?Wiki$" (siteinfo^-sitename siteinfo) "") - (config-get 'application_name))) - ,@(map (λ (url) - `(link (@ (rel "stylesheet") (type "text/css") (href ,url)))) - (required-styles (format "https://~a.fandom.com" wikiname))) - (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "main.css")))) - (script "const BWData = " - ,(jsexpr->string (hasheq 'wikiname wikiname - 'strict_proxy (config-true? 'strict_proxy)))) - ,(if (config-true? 'feature_search_suggestions) - `(script (@ (type "module") (src ,(get-static-url "search-suggestions.js")))) - "") - (link (@ (rel "icon") (href ,(u (λ (v) (config-true? 'strict_proxy)) - (λ (v) (u-proxy-url v)) - (head-data^-icon-url head-data)))))) - (body (@ (class ,(head-data^-body-class head-data))) - (div (@ (class "main-container")) - (div (@ (class "fandom-community-header__background tileHorizontally header"))) - (div (@ (class "page")) - (main (@ (class "page__main")) - ,(niwa-notice wikiname title) - (div (@ (class "custom-top")) - (h1 (@ (class "page-title")) ,title) - (nav (@ (class "sitesearch")) - (form (@ (action ,(format "/~a/search" wikiname)) - (class "bw-search-form") - (id "bw-pr-search-form")) - (label (@ (for "bw-search-input")) "Search ") - (div (@ (id "bw-pr-search-input")) - (input (@ (type "text") (name "q") (id "bw-search-input") (autocomplete "off")))) - (div (@ (class "bw-ss__container") (id "bw-pr-search-suggestions")))))) - (div (@ (id "content") #;(class "page-content")) - (div (@ (id "mw-content-text")) - ,content)) - ,(application-footer source-url #:license (siteinfo^-license siteinfo)))))))) + `(*TOP* + (*DECL* DOCTYPE html) + (html + (head + (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) + (title ,(format "~a | ~a+~a" + title + (regexp-replace #rx" ?Wiki$" (siteinfo^-sitename siteinfo) "") + (config-get 'application_name))) + ,@(map (λ (url) + `(link (@ (rel "stylesheet") (type "text/css") (href ,url)))) + (required-styles (format "https://~a.fandom.com" wikiname))) + (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "main.css")))) + (script "const BWData = " + ,(jsexpr->string (hasheq 'wikiname wikiname + 'strict_proxy (config-true? 'strict_proxy)))) + ,(if (config-true? 'feature_search_suggestions) + `(script (@ (type "module") (src ,(get-static-url "search-suggestions.js")))) + "") + (link (@ (rel "icon") (href ,(u (λ (v) (config-true? 'strict_proxy)) + (λ (v) (u-proxy-url v)) + (head-data^-icon-url head-data)))))) + (body (@ (class ,(head-data^-body-class head-data))) + (div (@ (class "main-container")) + (div (@ (class "fandom-community-header__background tileHorizontally header"))) + (div (@ (class "page")) + (main (@ (class "page__main")) + ,(niwa-notice wikiname title) + (div (@ (class "custom-top")) + (h1 (@ (class "page-title")) ,title) + (nav (@ (class "sitesearch")) + (form (@ (action ,(format "/~a/search" wikiname)) + (class "bw-search-form") + (id "bw-pr-search-form")) + (label (@ (for "bw-search-input")) "Search ") + (div (@ (id "bw-pr-search-input")) + (input (@ (type "text") (name "q") (id "bw-search-input") (autocomplete "off")))) + (div (@ (class "bw-ss__container") (id "bw-pr-search-suggestions")))))) + (div (@ (id "content") #;(class "page-content")) + (div (@ (id "mw-content-text")) + ,content)) + ,(application-footer source-url #:license (siteinfo^-license siteinfo))))))))) (module+ test (define page (parameterize ([(config-parameter 'strict_proxy) "true"]) diff --git a/src/page-home.rkt b/src/page-home.rkt index e430326..4cd9f3a 100644 --- a/src/page-home.rkt +++ b/src/page-home.rkt @@ -60,25 +60,27 @@ (p "If you want to create your own wiki, try Miraheze!"))) (define body - `(html - (head - (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) - (title "About | BreezeWiki") - (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "internal.css")))) - (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "main.css")))) - (link (@ (rel "icon") (href ,(head-data^-icon-url head-data-default))))) - (body (@ (class "skin-fandomdesktop theme-fandomdesktop-light internal")) - (div (@ (class "main-container")) - (div (@ (class "fandom-community-header__background tileBoth header"))) - (div (@ (class "page")) - (main (@ (class "page__main")) - (div (@ (class "custom-top")) - (h1 (@ (class "page-title")) - "About BreezeWiki")) - (div (@ (id "content") #;(class "page-content")) - (div (@ (id "mw-content-text")) - ,@content)) - ,(application-footer #f))))))) + `(*TOP* + (*DECL* DOCTYPE html) + (html + (head + (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) + (title "About | BreezeWiki") + (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "internal.css")))) + (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "main.css")))) + (link (@ (rel "icon") (href ,(head-data^-icon-url head-data-default))))) + (body (@ (class "skin-fandomdesktop theme-fandomdesktop-light internal")) + (div (@ (class "main-container")) + (div (@ (class "fandom-community-header__background tileBoth header"))) + (div (@ (class "page")) + (main (@ (class "page__main")) + (div (@ (class "custom-top")) + (h1 (@ (class "page-title")) + "About BreezeWiki")) + (div (@ (id "content") #;(class "page-content")) + (div (@ (id "mw-content-text")) + ,@content)) + ,(application-footer #f)))))))) (module+ test (check-not-false (xexp->html body))) diff --git a/src/page-wiki.rkt b/src/page-wiki.rkt index 4e0b73a..a0a2944 100644 --- a/src/page-wiki.rkt +++ b/src/page-wiki.rkt @@ -175,14 +175,15 @@ ; proxy images from inline styles, if strict_proxy is set (curry u (λ (v) (config-true? 'strict_proxy)) - (λ (v) (attribute-maybe-update 'style - (λ (style) - (regexp-replace #rx"url\\(['\"]?(.*?)['\"]?\\)" style - (λ (whole url) - (string-append - "url(" - (u-proxy-url url) - ")")))) v))) + (λ (v) (attribute-maybe-update + 'style + (λ (style) + (regexp-replace #rx"url\\(['\"]?(.*?)['\"]?\\)" style + (λ (whole url) + (string-append + "url(" + (u-proxy-url url) + ")")))) v))) ; and also their links, if strict_proxy is set (curry u (λ (v) diff --git a/src/static-data.rkt b/src/static-data.rkt index b7fc71a..9522639 100644 --- a/src/static-data.rkt +++ b/src/static-data.rkt @@ -12,7 +12,9 @@ (define built (simple-form-path (build-path path-static f))) (values built (file-or-directory-modify-seconds built)))) -(: get-static-url ((U String Path) -> String)) +(: get-static-url (Path-String -> String)) (define (get-static-url path-or-filename) - (define the-path (simple-form-path (if (path? path-or-filename) path-or-filename (build-path path-static path-or-filename)))) + (define the-path (simple-form-path (if (path? path-or-filename) + path-or-filename + (build-path path-static path-or-filename)))) (format "/static/~a?t=~a" (file-name-from-path the-path) (hash-ref static-data the-path))) diff --git a/src/xexpr-utils.rkt b/src/xexpr-utils.rkt index cd7f651..f5ef3cf 100644 --- a/src/xexpr-utils.rkt +++ b/src/xexpr-utils.rkt @@ -157,20 +157,32 @@ (define element-type (car element)) (define attributes (bits->attributes (cdr element))) (define contents (filter element-is-content? (cdr element))) ; provide elements and strings - (if (or (equal? element-type '*DECL) - (equal? element-type '@) - (equal? element-type '&)) - ; special element, do nothing - element - ; regular element, transform it - (match (transformer element element-type attributes contents) - [(list element-type attributes contents) - (append (list element-type) - (if (pair? attributes) (list (append '(@) attributes)) (list)) - (map (λ (content) - (if (element-is-element? content) (loop content) content)) - contents))])))) + (cond + [(equal? element-type '*DECL*) + ; declarations like get mapped as attributes as if the element were (*DECL* (@ (DOCTYPE) (html))) + (match (transformer element element-type (map list (cdr element)) null) + [(list element-type attributes contents) + `(*DECL* ,@(map car attributes))] + [#f ""])] + [(member element-type '(@ &)) + ; special element, do nothing + element] + [#t + ; regular element, transform it + (match (transformer element element-type attributes contents) + [(list element-type attributes contents) + (append (list element-type) + (if (pair? attributes) (list (append '(@) attributes)) (list)) + (map (λ (content) + (if (element-is-element? content) (loop content) content)) + contents))])]))) (module+ test + ; check doctype is preserved when present + (check-equal? (update-tree (λ (e t a c) (list t a c)) '(*TOP* (*DECL* DOCTYPE html) (html (body "Hey")))) + '(*TOP* (*DECL* DOCTYPE html) (html (body "Hey")))) + ; check doctype can be removed if desirable + (check-equal? (update-tree (λ (e t a c) (if (eq? t '*DECL*) #f (list t a c))) '(*TOP* (*DECL* DOCTYPE html) (html (body "Hey")))) + '(*TOP* "" (html (body "Hey")))) ; check (& x) sequences are preserved (check-equal? (update-tree (λ (e t a c) (list t a c)) '(body "Hey" (& nbsp) (a (@ (href "/"))))) '(body "Hey" (& nbsp) (a (@ (href "/"))))))