piratify: make it work with Hugo 0.123 #778

This commit is contained in:
Sören Weber 2024-02-22 23:02:29 +01:00
parent e516a1bdd1
commit 3333a4133d
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 17 additions and 8 deletions

View file

@ -7,7 +7,7 @@ A theme for [Hugo](https://gohugo.io/) designed for documentation.
[★ What's new in the latest release ★](basics/migration) [★ What's new in the latest release ★](basics/migration)
![Image of the Relearn theme in light and dark mode on phone, tablet and desktop](images/hero.png?width=100%&height=100%) ![Image of the Relearn theme in light and dark mode on phone, tablet and desktop](/images/hero.png?width=100%&height=100%)
## Motivation ## Motivation

View file

@ -8,8 +8,6 @@
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }} {{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
{{- $langtrg := "pir" }} {{- $langtrg := "pir" }}
{{- $langsrc := cond (eq $page.Language.Lang $langtrg) (.langsrc | default "en") $page.Language.Lang }} {{- $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 }} {{- $l := $page.RelPermalink }}
{{- $c := "" }} {{- $c := "" }}
{{- $srcPage := "" }} {{- $srcPage := "" }}
@ -34,6 +32,7 @@
{{- break }} {{- break }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- $y := $c }}
{{- if eq $page.Language.Lang $langtrg }} {{- if eq $page.Language.Lang $langtrg }}
{{- if $writenotice }} {{- if $writenotice }}
{{- partial "shortcodes/notice.html" (dict {{- partial "shortcodes/notice.html" (dict
@ -111,7 +110,9 @@
"(\\w)(?:[aeiou])mizes([\\s\\n<.,;?!:])" "'mizes" "(\\w)(?:[aeiou])mizes([\\s\\n<.,;?!:])" "'mizes"
"(\\w)(?:[aeiou])nize([\\s\\n<.,;?!:])" "'nize" "(\\w)(?:[aeiou])nize([\\s\\n<.,;?!:])" "'nize"
"(\\w)(?:[aeiou])nizes([\\s\\n<.,;?!:])" "'nizes" "(\\w)(?:[aeiou])nizes([\\s\\n<.,;?!:])" "'nizes"
(printf "(href)=\"%s([^\"]*?\")" $baseURLpath) (printf "=\"%s%s/" $baseURLpath $langtrg) -}}
{{- $links := slice
"href"
-}} -}}
{{- $fix := dict {{- $fix := dict
"warn'n" "warning" "warn'n" "warning"
@ -125,13 +126,21 @@
{{- range $from, $to := $specials }} {{- range $from, $to := $specials }}
{{- $c = replaceRE $from (printf "${1}%s${2}" $to) $c }} {{- $c = replaceRE $from (printf "${1}%s${2}" $to) $c }}
{{- end }} {{- end }}
{{- range $attr := $links }}
{{- $c = replaceRE (printf "\\b(%s)(=\"[^\"]*?\")" $attr) "${1} data-piratify${2}" $c }}
{{- $m := findRESubmatch (printf "%s data-piratify=\"([^\"]*?)\"" $attr) $c }}
{{- range $m }}
{{- $r := printf "%s=\"%s\"" $attr (index . 1) }}
{{- $u := urls.Parse (index . 1) }}
{{- if and (not $u.IsAbs) $u.Path }}
{{- $r = printf "%s=\"/%s%s\"" $attr $langtrg (index . 1) }}
{{- end }}
{{- $c = replace $c (index . 0) $r }}
{{- end }}
{{- end }}
{{- range $from, $to := $fix }} {{- range $from, $to := $fix }}
{{- $c = replace $c $from $to }} {{- $c = replace $c $from $to }}
{{- end }} {{- end }}
{{- if (int (len $l)) }}
{{- $c = replaceRE "(src|href)=\"(images/[^\"]*?\")" (printf "${1}=\"%s${2}" $l) $c }}
{{- end }}
{{- $c = replaceRE (printf "(src|href)=\"([^\"]*?)/%s/([^\"]*?.files/[^\"]*?\")" $langtrg) "${1}=\"${2}/${3}" $c }}
{{- if $srcPage }} {{- if $srcPage }}
{{- range $page.Site.Params.relearn.dependencies }} {{- range $page.Site.Params.relearn.dependencies }}
{{- $has := printf "has%s" .name }} {{- $has := printf "has%s" .name }}