Skip to content

Commit

Permalink
theme: edge cases for multilang portable links #377
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Oct 26, 2023
1 parent 087c77d commit 1ff5026
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 8 additions & 6 deletions exampleSite/content/basics/migration/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ This document shows you what's new in the latest release. For a detailed list of

The following types of linking are supported:

| link | description |
| -------------------------------- | ------------------------------- |
| `[generator](basics/generator)` | absolute from your project root |
| `[generator](/basics/generator)` | absolute from your project root |
| `[generator](./../generator)` | relative from the current page |
| `[generator](../generator)` | relative from the current page |
| link | description |
| ---------------------------------- | ------------------------------------------- |
| `[generator](en/basics/generator)` | absolute from your project root (multilang) |
| `[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 |

---

Expand Down
13 changes: 6 additions & 7 deletions layouts/partials/shortcodes/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
{{- with $url.Fragment }}
{{- $fragment = printf "#%s" . }}
{{- end }}
{{- $path := strings.TrimSuffix ".html" $url.Path }}
{{- $path := $url.Path }}
{{- with $page.Page.GetPage $path }}
{{- $path := printf "%s/" (strings.TrimPrefix "/" (strings.TrimSuffix "/" $url.Path)) }}
{{- with $page.Page.GetPage (strings.TrimSuffix "/" $path | default "/") }}
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
{{- $found = true }}
{{- else }}
{{- /* is it a link into another translation? */}}
{{- range $page.Site.Languages }}
{{- $lang := .Lang }}
{{- $prefix := printf "/%s" $lang }}
{{- if strings.HasPrefix $prefix $path }}
{{- $path := strings.TrimPrefix $prefix $path }}
{{- with $page.Page.GetPage $path }}
{{- $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 }}
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
Expand Down

0 comments on commit 1ff5026

Please sign in to comment.