2023-07-27 14:14:55 +00:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2023-11-20 23:53:33 +00:00
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'piratify' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
2023-07-27 14:14:55 +00:00
{{- end }}
2023-02-08 21:17:27 +00:00
{{- $content := .content }}
{{- $pagefield := cond (ne $content nil) nil (.pagefield | default "Content") }}
2023-02-10 16:30:41 +00:00
{{- $writenotice := cond (ne .writenotice nil) .writenotice false }}
2023-02-08 21:17:27 +00:00
{{- $langtrg := "pir" }}
2023-11-28 20:31:35 +00:00
{{- $langsrc := cond (eq $page.Language.Lang $langtrg) (.langsrc | default "en") $page.Language.Lang }}
2023-07-27 14:14:55 +00:00
{{- $l := $page.RelPermalink }}
2023-02-08 21:17:27 +00:00
{{- $c := "" }}
2023-07-27 14:14:55 +00:00
{{- $srcPage := "" }}
2023-05-18 12:03:39 +00:00
{{- if ne $content nil }}
{{- $c = $content }}
{{- else if eq $pagefield "Content" }}
2023-07-27 14:14:55 +00:00
{{- $c = $page.Content }}
2023-05-18 12:03:39 +00:00
{{- else if eq $pagefield "TableOfContents" }}
2023-07-27 14:14:55 +00:00
{{- $c = $page.TableOfContents }}
2023-05-18 12:03:39 +00:00
{{- end }}
2023-07-27 14:14:55 +00:00
{{- range $page.AllTranslations }}
2023-02-08 21:17:27 +00:00
{{- if eq .Language.Lang $langsrc }}
{{- $l = .RelPermalink }}
{{- if ne $content nil }}
{{- $c = $content }}
{{- else if eq $pagefield "Content" }}
{{- $c = .Content }}
2023-07-27 14:11:46 +00:00
{{- $srcPage = . }}
2023-02-08 21:17:27 +00:00
{{- else if eq $pagefield "TableOfContents" }}
{{- $c = .TableOfContents }}
{{- end }}
{{- break }}
{{- end }}
{{- end }}
2024-02-22 22:02:29 +00:00
{{- $y := $c }}
2023-11-28 20:31:35 +00:00
{{- if eq $page.Language.Lang $langtrg }}
2023-02-08 21:17:27 +00:00
{{- if $writenotice }}
{{- partial "shortcodes/notice.html" (dict
2023-07-27 14:14:55 +00:00
"page" $page
2023-07-27 14:11:46 +00:00
"content" "< p > Fello' pirrrates, grog made us dizzy! Be awarrre < b > some stuff may look weird< / b > in this trrranslat'n. Like < b > Merrrmaids< / b > , do'n < b > math or chemistrrry< / b > and stuff.< / p > \n"
2023-02-08 21:17:27 +00:00
"icon" "skull-crossbones"
"style" "warning"
"title" "Arrr! Pirrrates"
) }}
{{- end }}
{{- $words := dict
"Hugo" "Cap'n Hugo"
"Info" "Ahoi"
"Note" "Avast"
"Tip" "Smarrrt Arrrse"
"Warning" "Arrr"
"good" "bloody"
"shortcodes" "shorrrtcodes"
"Shortcodes" "Shorrrtcodes"
"Mermaid" "Merrrmaid"
"Markdown" "Marrrkdown"
"Markup" "Marrrkup"
"markup" "marrrkup"
"for" "fer"
"Your" "Yer"
"your" "yer"
"You" "Ye"
"you" "ye"
"the" "th'"
"The" "Th'"
"is" "be"
"Is" "Be"
"are" "be"
"Are" "Be"
"Of" "O'"
"of" "o'"
"To" "T'"
"to" "t'"
"in" "'n"
"With" "Wit'"
"with" "wit'"
"Where" "Whar'"
"where" "whar'"
"After" "Aft"
"And" "An'"
"and" "an'"
"Load" "Board"
"load" "board"
"Loaded" "Boarded"
"loaded" "boarded"
"Content" "Rrrambling"
"content" "rrrambling"
"icon" "ay'con"
"Icon" "Ay'con"
"icons" "ay'cons"
"Icons" "Ay'cons"
"syntax" "rules"
"Syntax" "Rules"
"Site" "Ship"
"site" "ship"
"Page" "Plank"
"page" "plank"
"Pages" "Planks"
"pages" "planks"
"Relearn" "Relearrrn"
"Learn" "Learrrn"
-}}
{{- $specials := dict
"(\\w)ing([\\s\\n< . , ; ? ! : ] ) " " ' n "
"(\\w)ings([\\s\\n< . , ; ? ! : ] ) " " ' ns "
"(\\w)tion([\\s\\n< . , ; ? ! : ] ) " " t ' n "
"(\\w)tions([\\s\\n< . , ; ? ! : ] ) " " t ' ns "
"(\\w)(?:[aeiou])ble([\\s\\n< . , ; ? ! : ] ) " " ' ble "
"(\\w)(?:[aeiou])mize([\\s\\n< . , ; ? ! : ] ) " " ' mize "
"(\\w)(?:[aeiou])mizes([\\s\\n< . , ; ? ! : ] ) " " ' mizes "
"(\\w)(?:[aeiou])nize([\\s\\n< . , ; ? ! : ] ) " " ' nize "
"(\\w)(?:[aeiou])nizes([\\s\\n< . , ; ? ! : ] ) " " ' nizes "
2024-02-22 22:02:29 +00:00
-}}
{{- $links := slice
"href"
2023-02-08 21:17:27 +00:00
-}}
{{- $fix := dict
"warn'n" "warning"
"sect'n" "section"
"n Cap'n" "n"
"Avast right o' John" "Note right of John"
-}}
{{- range $from, $to := $words }}
{{- $c = replaceRE (printf "([\\s\\n>])%s([\\s\\n< . , ; ? ! : ] ) " $ from ) ( printf " $ { 1 } % s $ { 2 } " $ to ) $ c } }
{{- end }}
{{- range $from, $to := $specials }}
{{- $c = replaceRE $from (printf "${1}%s${2}" $to) $c }}
{{- end }}
2024-02-22 22:02:29 +00:00
{{- 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 }}
2023-02-08 21:17:27 +00:00
{{- range $from, $to := $fix }}
{{- $c = replace $c $from $to }}
{{- end }}
2023-07-27 14:11:46 +00:00
{{- if $srcPage }}
2023-10-09 15:42:51 +00:00
{{- range $page.Site.Params.relearn.dependencies }}
{{- $has := printf "has%s" .name }}
{{- $page.Store.Set $has (or ($page.Store.Get $has) ($srcPage.Store.Get $has)) }}
{{- end }}
2023-07-27 14:11:46 +00:00
{{- end }}
2023-02-08 21:17:27 +00:00
{{- end }}
{{ $c | safeHTML }}