theme: edge cases for multilang portable links #377

This commit is contained in:
Sören Weber 2023-10-26 22:47:15 +02:00
parent 087c77dff0
commit 1ff5026bec
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 14 additions and 13 deletions

View file

@ -58,9 +58,11 @@ This document shows you what's new in the latest release. For a detailed list of
The following types of linking are supported: The following types of linking are supported:
| link | description | | link | description |
| -------------------------------- | ------------------------------- | | ---------------------------------- | ------------------------------------------- |
| `[generator](basics/generator)` | absolute from your project root | | `[generator](en/basics/generator)` | absolute from your project root (multilang) |
| `[generator](/basics/generator)` | absolute from your project root | | `[generator](/en/basics/generator)`| absolute from your project root (multilang) |
| `[generator](basics/generator)` | absolute from your current language root |
| `[generator](/basics/generator)` | absolute from your current language root |
| `[generator](./../generator)` | relative from the current page | | `[generator](./../generator)` | relative from the current page |
| `[generator](../generator)` | relative from the current page | | `[generator](../generator)` | relative from the current page |

View file

@ -25,19 +25,18 @@
{{- with $url.Fragment }} {{- with $url.Fragment }}
{{- $fragment = printf "#%s" . }} {{- $fragment = printf "#%s" . }}
{{- end }} {{- end }}
{{- $path := strings.TrimSuffix ".html" $url.Path }} {{- $path := printf "%s/" (strings.TrimPrefix "/" (strings.TrimSuffix "/" $url.Path)) }}
{{- $path := $url.Path }} {{- with $page.Page.GetPage (strings.TrimSuffix "/" $path | default "/") }}
{{- with $page.Page.GetPage $path }}
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }} {{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
{{- $found = true }} {{- $found = true }}
{{- else }} {{- else }}
{{- /* is it a link into another translation? */}} {{- /* is it a link into another translation? */}}
{{- range $page.Site.Languages }} {{- range $page.Site.Languages }}
{{- $lang := .Lang }} {{- $lang := .Lang }}
{{- $prefix := printf "/%s" $lang }} {{- $prefix := printf "%s/" $lang }}
{{- if strings.HasPrefix $prefix $path }} {{- if strings.HasPrefix $path $prefix }}
{{- $path := strings.TrimPrefix $prefix $path }} {{- $path = strings.TrimPrefix $prefix $path | default "/" }}
{{- with $page.Page.GetPage $path }} {{- with $page.Site.GetPage (strings.TrimSuffix "/" $path | default "/") }}
{{- range .Page.AllTranslations }} {{- range .Page.AllTranslations }}
{{- if eq $lang .Lang }} {{- if eq $lang .Lang }}
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }} {{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}