2025-02-16 00:03:08 +01:00
|
|
|
{{- $u := urls.Parse .url }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- $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 . }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- 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 }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- $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 }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- 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 . }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- 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" . }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- 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 }}
|
2025-02-08 16:05:12 +01:00
|
|
|
{{- 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 }}
|