links: handle links to not fully translated pages #377

This commit is contained in:
Sören Weber 2023-10-28 00:37:39 +02:00
parent 8b0214e9a5
commit ff61932b70
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -31,22 +31,18 @@
{{- $found = true }}
{{- else }}
{{- /* is it a link into another translation? */}}
{{- range $page.Site.Languages }}
{{- $lang := .Lang }}
{{- range $page.Sites }}
{{- $lang := .Language.Lang }}
{{- $prefix := printf "%s/" $lang }}
{{- if strings.HasPrefix $path $prefix }}
{{- $path = strings.TrimPrefix $prefix $path | default "/" }}
{{- with $page.Site.GetPage (strings.TrimSuffix "/" $path | default "/") }}
{{- range .Page.AllTranslations }}
{{- if eq $lang .Lang }}
{{- with .GetPage (strings.TrimSuffix "/" $path | default "/") }}
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
{{- $found = true }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if not $found }}
{{- warnf "%q: no page was found for link '%s'" $page.File.Filename $url.Path }}
{{- end }}