diff --git a/lib/tree-updater.rkt b/lib/tree-updater.rkt
index 074c5a1..0dbf695 100644
--- a/lib/tree-updater.rkt
+++ b/lib/tree-updater.rkt
@@ -12,17 +12,12 @@
update-tree-wiki)
(define (preprocess-html-wiki html)
- (define ((rr* find replace) contents)
- (regexp-replace* find contents replace))
- ((compose1
- ; fix navbox list nesting
- ; navbox on right of page has incorrect html "
" and the xexpr parser puts the much further up the tree
- ; add a to make the parser happy
- ; usage: /fallout/wiki/Fallout:_New_Vegas_achievements_and_trophies
- (rr* #rx"(]*>\n?)(- )" "\\1
\\2")
- ; change to to make the parser happy
- (rr* #rx"(]*>)[ \t]*([^<]*) " "\\1\\2"))
- html))
+ (regexp-replace* #rx"(<(?:td|figcaption)[^>]*?>\n?)(?:- |[ \t]*?
(.*?) )"
+ html (λ (whole first-tag [contents #f])
+ (if (eq? (string-ref whole 1) #\f) ;; figcaption
+ (string-append first-tag "" contents "")
+ (string-append first-tag "- ")))))
+
(module+ test
(check-equal? (preprocess-html-wiki "
\n- Hey
")
" | \n- Hey
")
@@ -66,6 +61,11 @@
(iframe (@ (src "https://example.com/iframe-src")))))))
(define (updater wikiname #:strict-proxy? [strict-proxy? #f])
+ ;; precompute wikiurl regex for efficency
+ (define wikiurl-regex (pregexp (format "^https://(~a)\\.fandom\\.com(/wiki/.*)$" px-wikiname)))
+ ;; precompute link replacement string for efficiency
+ (define wiki-substitution (format "/~a\\1" wikiname))
+
(define classlist-updater
(compose1
; uncollapse all navbox items (bottom of page mass navigation)
@@ -110,8 +110,8 @@
(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) (regexp-replace #rx"^(/wiki/.*)$" href wiki-substitution))
+ (λ (href) (regexp-replace wikiurl-regex href "/\\1\\2")))
href)))
; add noreferrer to a.image
(curry u
diff --git a/lib/xexpr-utils.rkt b/lib/xexpr-utils.rkt
index 018d8c3..cb40510 100644
--- a/lib/xexpr-utils.rkt
+++ b/lib/xexpr-utils.rkt
@@ -190,7 +190,9 @@
'(body "Hey" (& nbsp) (a (@ (href "/"))))))
(define (has-class? name attributes)
- (and (member name (string-split (or (get-attribute 'class attributes) "") " ")) #t))
+ ;; 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))
(module+ test
(check-true (has-class? "red" '((class "yellow red blue"))))
(check-false (has-class? "red" '((class "yellow blue"))))
diff --git a/src/extwiki-generic.rkt b/src/extwiki-generic.rkt
index fe30b14..113b139 100644
--- a/src/extwiki-generic.rkt
+++ b/src/extwiki-generic.rkt
@@ -110,8 +110,8 @@
(div (@ (class "niwa__left"))
(a (@ (class "niwa__go") (href ,go)) "Read " ,title " on " ,display-name " →")
,@body
- (p "This wiki's core community has wholly migrated away from Fandom. You should "
- (a (@ (href ,go)) "go to " ,display-name " now!")))
+ (p "This external wiki is a helpful alternative to Fandom. You should "
+ (a (@ (href ,go)) "check it out now!")))
,(if logo
`(div (@ (class "niwa__right"))
(img (@ (class "niwa__logo") (src ,logo))))
|
| |