Created
December 29, 2024 08:14
-
-
Save matsuoshi/5e8507956a1390dac8657c308a1d96e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {{/* | |
| From https://quinncasey.com/hugo-wikilink-support/ | |
| */}} | |
| {{ $wikiregexWithText := "\\[\\[([^\\]\\|\\r\\n]+?)\\|([^\\]\\|\\r\\n]+?)\\]\\]" }} | |
| {{ $wikiregex := "\\[\\[([^\\]\\|\\r\\n]+?)\\]\\]" }} | |
| {{ $page := .Page }} | |
| {{ $pageContent := .Content }} | |
| {{ range ($wikilinks := .Content | findRE $wikiregex) }} | |
| {{ $link := . | replaceRE $wikiregex "$1" }} | |
| {{ $wikilink := printf "\\[\\[%s\\]\\]" $link }} | |
| {{ with relref $page $link }} | |
| {{ $link := printf "%s%s%s%s%s" "<a href=\"" . "\">" ($.Site.GetPage $link).Title "</a>" }} | |
| {{ $pageContent = $pageContent | replaceRE $wikilink $link }} | |
| {{ end }} | |
| {{ end }} | |
| {{ range ($pageContent | findRE $wikiregexWithText) }} | |
| {{ $link := . | replaceRE $wikiregexWithText "$1" }} | |
| {{ $text := . | replaceRE $wikiregexWithText "$2" }} | |
| {{ $wikilink := printf "\\[\\[%s\\|%s\\]\\]" $link $text }} | |
| {{ with relref $page $link }} | |
| {{ $link := printf "%s%s%s%s%s" "<a href=\"" . "\">" $text "</a>" }} | |
| {{ $pageContent = $pageContent | replaceRE $wikilink $link }} | |
| {{ end }} | |
| {{ end }} | |
| {{ $pageContent | safeHTML }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment