piratify: reintroduce baseURL

for GitHub
This commit is contained in:
Sören Weber 2024-02-24 15:10:05 +01:00
parent 2fe2ef2b7e
commit b54661e705
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -8,6 +8,8 @@
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
{{- $langtrg := "pir" }}
{{- $langsrc := cond (eq $page.Language.Lang $langtrg) (.langsrc | default "en") $page.Language.Lang }}
{{- $baseURL := urls.Parse site.BaseURL }}
{{- $baseURLpath := $baseURL.Path | default "/" }}
{{- $l := $page.RelPermalink }}
{{- $c := "" }}
{{- $srcPage := "" }}
@ -32,7 +34,6 @@
{{- break }}
{{- end }}
{{- end }}
{{- $y := $c }}
{{- if eq $page.Language.Lang $langtrg }}
{{- if $writenotice }}
{{- partial "shortcodes/notice.html" (dict
@ -127,13 +128,13 @@
{{- $c = replaceRE $from (printf "${1}%s${2}" $to) $c }}
{{- end }}
{{- range $attr := $links }}
{{- $c = replaceRE (printf "\\b(%s)(=\"[^\"]*?\")" $attr) "${1} data-piratify${2}" $c }}
{{- $m := findRESubmatch (printf "%s data-piratify=\"([^\"]*?)\"" $attr) $c }}
{{- $c = replaceRE (printf "\\b(%s)(=\"%s[^\"]*?\")" $attr $baseURLpath) "${1} data-piratify${2}" $c }}
{{- $m := findRESubmatch (printf "%s data-piratify=\"(%s)([^\"]*?)\"" $attr $baseURLpath) $c }}
{{- range $m }}
{{- $r := printf "%s=\"%s\"" $attr (index . 1) }}
{{- $u := urls.Parse (index . 1) }}
{{- $r := printf "%s=\"%s\"" $attr (index . 2) }}
{{- $u := urls.Parse (index . 2) }}
{{- if and (not $u.IsAbs) $u.Path }}
{{- $r = printf "%s=\"/%s%s\"" $attr $langtrg (index . 1) }}
{{- $r = printf "%s=\"%s%s/%s\"" $attr $baseURLpath $langtrg (index . 2) }}
{{- end }}
{{- $c = replace $c (index . 0) $r }}
{{- end }}