hugo-theme-relearn/layouts/partials/_relearn/decoratedLink.gotmpl

66 lines
2.8 KiB
Go Template
Raw Permalink Normal View History

2025-02-16 00:03:08 +01:00
{{- $u := urls.Parse .url }}
{{- $hideFilepath := .hideFilepath | default false }}
{{- $type := printf "%T" .linkObject }}
{{- $isPage := eq $type "*hugolib.pageState" }}
{{- $href := partial "permalink.gotmpl" (dict "to" .linkObject) }}
{{- if $isPage }}
{{- $format := $u.Query.Get "format" }}
{{- if $format }}
{{- $of := .linkObject.OutputFormats.Get $format }}
{{- if $of }}
{{- $href = partial "permalink.gotmpl" (dict "to" $of) }}
{{- else }}
{{- $msg := printf "output format %q not found" $of }}
{{- partial "partials/inline/print-error" (dict "url" .url "page" .page "param" .param "msg" $msg "linkObject" .linkObject "hideFilepath" $hideFilepath) }}
{{- end }}
{{- end }}
{{- end }}
2025-02-16 00:03:08 +01:00
{{- with $u.RawQuery }}
{{- $href = printf "%s?%s" $href . }}
{{- end }}
{{- with $u.Fragment }}
{{- $href = printf "%s#%s" $href . }}
{{- if $isPage }}
{{- partial "inline/validate-fragment.html" (dict "page" $.page "linkObject" $.linkObject "parsedURL" $u "url" $.url "param" $.param "hideFilepath" $hideFilepath) }}
2025-02-16 00:03:08 +01:00
{{- end }}
{{- end }}
{{- $href = replaceRE `&lang=\w*\b` "" $href }}
{{- $href = replaceRE `\?lang=\w*&\b` "?" $href }}
{{- $href = replaceRE `\?lang=\w*\b` "" $href }}
{{- $href = replaceRE `&format=\w*\b` "" $href }}
{{- $href = replaceRE `\?format=\w*&\b` "?" $href }}
{{- $href = replaceRE `\?format=\w*\b` "" $href }}
2025-02-16 00:03:08 +01:00
{{- return $href }}
{{- define "partials/inline/validate-fragment.html" }}
{{- $u := .parsedURL }}
{{- with $u.Fragment }}
{{- if $.linkObject.Fragments.Identifiers.Contains . }}
{{- if gt ($.linkObject.Fragments.Identifiers.Count .) 1 }}
{{- $filepath := "[virtual file]" }}{{ with and $.page $.page.File $.page.File.Filename }}{{ $filepath = . }}{{ end }}
2025-02-16 00:03:08 +01:00
{{- $msg := printf "%q: duplicate heading ID %q found" $filepath . }}
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" $.url "page" $.page "param" $.param "msg" $msg) }}
2025-02-16 00:03:08 +01:00
{{- end }}
{{- else }}
{{- $msg := printf "heading ID %q not found" . }}
{{- partial "partials/inline/print-error" (dict "url" $.url "page" $.page "param" $.param "msg" $msg "linkObject" $.linkObject "hideFilepath" $.hideFilepath) }}
2025-02-16 00:03:08 +01:00
{{- end }}
{{- end }}
{{- end }}
{{- define "partials/inline/print-error" }}
{{- $targetpath := "" }}
{{- with .linkObject.File }}
{{- $targetpath = .Path }}
{{- else }}
{{- $targetpath = .Path }}
{{- end }}
{{- $filepath := "[virtual file]" }}{{ with and .page .page.File .page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- $msg := .msg }}
{{- if not .hideFilepath }}
{{- $msg = printf "%q: %s" $filepath $msg }}
{{- end }}
{{- if or .hideFilepath (ne .page .linkObject) }}
{{- $msg = printf "%s in %q" $msg $targetpath }}
{{- end }}
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .url "page" .page "param" .param "msg" $msg) }}
{{- end }}