hugo-theme-relearn/layouts/partials/menupermalink.gotmpl

30 lines
1.3 KiB
Go Template
Raw Normal View History

2024-10-22 19:35:10 +02:00
{{- $url := "" }}
2025-01-29 18:03:23 +01:00
{{- with .menu }}
{{- $errorlevel := or $.page.Params.link.errorlevel $.page.Site.Params.link.errorlevel }}
{{- if .PageRef }}
{{- with .Page }}
{{- $url = partial "permalink.gotmpl" (dict "to" .) }}
{{- else }}
{{- if eq $errorlevel "warning" }}
{{- warnf "%q: menu link '%s' is not a page but linked anyways" $.page.File.Filename .PageRef }}
{{- else if eq $errorlevel "error" }}
{{- errorf "%q: menu link '%s' is not a page" $.page.File.Filename .PageRef }}
{{- end }}
{{- end }}
{{- else }}
{{- with .URL }}
{{- $url = . | relLangURL }}
{{- $u := urls.Parse $url }}
{{- if $u.IsAbs }}
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" $url "page" $.page "type" "menu link") $u.String }}
{{- else }}
{{- if eq $errorlevel "warning" }}
{{- warnf "%q: local menu link '%s' was given by 'URL'; if it points to a page inside your Hugo site use 'pageRef' instead; link created anyways" $.page.File.Filename . }}
{{- else if eq $errorlevel "error" }}
{{- errorf "%q: local menu link '%s' was given by 'URL'; if it points to a page inside your Hugo site use 'pageRef' instead" $.page.File.Filename . }}
{{- end }}
{{- end }}
{{- end }}
2024-10-22 19:35:10 +02:00
{{- end }}
{{- end }}
{{- return $url }}