diff --git a/lib/tree-updater.rkt b/lib/tree-updater.rkt index 879ff90..074c5a1 100644 --- a/lib/tree-updater.rkt +++ b/lib/tree-updater.rkt @@ -100,29 +100,19 @@ (define (cardimage-class-updater c) (string-append c " bw-updated-cardtable-cardimage")) - ; precompute wikiurl regex for efficency - (define wikiurl-regex (pregexp (format "^https://(~a)\\.fandom\\.com(/wiki/.*)$" px-wikiname))) - (define attributes-updater (compose1 ; uncollapsing #;(curry attribute-maybe-update 'class (λ (class) (string-join (classlist-updater (string-split class " ")) " "))) (curry attribute-maybe-update 'class class-updater) - ; change links to stay on the same wiki - (let - ; precompute wikiname replacement pattern - ([wiki-substitution (format "/~a\\1" wikiname)]) - (curry attribute-maybe-update 'href - (λ (href) - ((compose1 - ; ok so these don't actually depend on each other. - ; one will match or the other - ; also we don't really need regex here. - (λ (href) (regexp-replace #rx"^(/wiki/.*)$" href wiki-substitution)) - (λ (href) (regexp-replace wikiurl-regex href "/\\1\\2"))) - href)))) + (curry attribute-maybe-update 'href + (λ (href) + ((compose1 + (λ (href) (regexp-replace #rx"^(/wiki/.*)" href (format "/~a\\1" wikiname))) + (λ (href) (regexp-replace (pregexp (format "^https://(~a)\\.fandom\\.com(/wiki/.*)" px-wikiname)) href "/\\1\\2"))) + href))) ; add noreferrer to a.image (curry u (λ (v) (and #;(eq? element-type 'a) diff --git a/lib/xexpr-utils.rkt b/lib/xexpr-utils.rkt index b1538d6..018d8c3 100644 --- a/lib/xexpr-utils.rkt +++ b/lib/xexpr-utils.rkt @@ -190,9 +190,7 @@ '(body "Hey" (& nbsp) (a (@ (href "/")))))) (define (has-class? name attributes) - ; splitting without specifying separator or splitting on #px"\\s+" makes - ; string-split use a faster whitespace-specialized implementation. - (and (member name (string-split (or (get-attribute 'class attributes) "") #px"\\s+")) #t)) + (and (member name (string-split (or (get-attribute 'class attributes) "") " ")) #t)) (module+ test (check-true (has-class? "red" '((class "yellow red blue")))) (check-false (has-class? "red" '((class "yellow blue"))))