Compare commits
4 commits
8274e6cf1f
...
d3187cc310
Author | SHA1 | Date | |
---|---|---|---|
d3187cc310 | |||
ba6c5be990 | |||
|
f5529ed12a | ||
|
3f1946a3b8 |
3 changed files with 18 additions and 16 deletions
|
@ -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 "<td ...><li>" and the xexpr parser puts the <li> much further up the tree
|
||||
; add a <ul> to make the parser happy
|
||||
; usage: /fallout/wiki/Fallout:_New_Vegas_achievements_and_trophies
|
||||
(rr* #rx"(<td[^>]*>\n?)(<li>)" "\\1<ul>\\2")
|
||||
; change <figcaption><p> to <figcaption><span> to make the parser happy
|
||||
(rr* #rx"(<figcaption[^>]*>)[ \t]*<p class=\"caption\">([^<]*)</p>" "\\1<span class=\"caption\">\\2</span>"))
|
||||
html))
|
||||
(regexp-replace* #rx"(<(?:td|figcaption)[^>]*?>\n?)(?:<li>|[ \t]*?<p class=\"caption\">(.*?)</p>)"
|
||||
html (λ (whole first-tag [contents #f])
|
||||
(if (eq? (string-ref whole 1) #\f) ;; figcaption
|
||||
(string-append first-tag "<span class=\"caption\">" contents "</span>")
|
||||
(string-append first-tag "<ul><li>")))))
|
||||
|
||||
(module+ test
|
||||
(check-equal? (preprocess-html-wiki "<td class=\"va-navbox-column\" style=\"width: 33%\">\n<li>Hey</li>")
|
||||
"<td class=\"va-navbox-column\" style=\"width: 33%\">\n<ul><li>Hey</li>")
|
||||
|
@ -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
|
||||
|
|
|
@ -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"))))
|
||||
|
|
|
@ -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))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue