|
4 | 4 |
|
5 | 5 | Localization link processing
|
6 | 6 |
|
7 |
| - The following code block will prefix the page language code to an |
8 |
| - absolute path when: |
| 7 | + The following code will prefix $url with the language code of this page when: |
9 | 8 |
|
10 | 9 | - This page's localization isn't the default localization (English)
|
11 |
| - - The URL is an absolute path that doesn't start with any of the following: |
12 |
| - - A language code, such as `ja` |
13 |
| - - A path segment other than `docs`, since current OTel localizations only |
14 |
| - offer translations for at most doc pages. |
| 10 | + - $url is an absolute path -- that is, it starts with / |
| 11 | + - The $url target page exists in this locale |
15 | 12 |
|
16 | 13 | */ -}}
|
17 | 14 |
|
18 |
| -{{ $defaultLang := "en" -}} {{/* TODO: can we avoid hard coding this value? */ -}} |
19 |
| -{{ $lang := .Page.Language.Lang -}} |
20 |
| -{{ if ne $lang $defaultLang -}} |
21 |
| - {{ $langPathPrefix := add "/" $lang "/" -}} |
22 |
| - {{ if and (hasPrefix $url $langPathPrefix) .Page.File -}} |
23 |
| - {{ warnf "File %s: avoid prefixing the following link path with '%s': %s" |
24 |
| - .Page.File.Filename $langPathPrefix $url -}} |
25 |
| - {{ else if and (hasPrefix $url "/") |
26 |
| - (not (findRE "^/(blog|community|docs/specs|ecosystem|status)/?" $url)) |
27 |
| - -}} |
28 |
| - {{ if and false (not (findRE "^/[a-z][a-z](-[a-zA-Z]{2})?/" $url)) -}} |
29 |
| - {{ $url = add $langPathPrefix (strings.TrimPrefix "/" $url) -}} |
| 15 | +{{ if hasPrefix $url "/" -}} |
| 16 | + {{/* Hard-coded default lang since it's what's most efficient and won't change :) */ -}} |
| 17 | + {{ $defaultLang := "en" -}} |
| 18 | + {{ $lang := .Page.Language.Lang -}} |
| 19 | + {{ if ne $lang $defaultLang -}} |
| 20 | + {{ $langPathPrefix := add "/" $lang "/" -}} |
| 21 | + {{ if and (hasPrefix $url $langPathPrefix) .Page.File -}} |
| 22 | + {{ warnf "File %s: drop unnecessary '%s' prefix from %s" |
| 23 | + .Page.File.Filename $langPathPrefix $url -}} |
| 24 | + {{ else -}} |
| 25 | + {{ $u := urls.Parse $url -}} |
| 26 | + {{ $localizedPagePath := add $langPathPrefix (strings.TrimPrefix "/" $url) -}} |
| 27 | + {{/* |
| 28 | + Look for the page (referenced by $url) in this page's locale's site. |
| 29 | + Note that .Page.GetPage exclusively looks for the given path in the same locale as .Page. |
| 30 | + */ -}} |
| 31 | + {{ with .Page.GetPage $u.Path -}} |
| 32 | + {{/* warnf "Found url %s -> page %s. -- relRef %s" $localizedPagePath . (.RelRef (dict "path" $url))*/ -}} |
| 33 | + {{/* Assert (eq $localizedPagePath (.RelRef (dict "path" $url))) */ -}} |
| 34 | + {{ $url = $localizedPagePath -}} |
| 35 | + {{ else -}} |
| 36 | + {{/* Use $url as is, letting the link checker report any issues. */ -}} |
| 37 | + {{/* warnf "Render-link: locale %s doesn't have the page %s (%s)" $lang $url $localizedPagePath */ -}} |
| 38 | + {{ end -}} |
30 | 39 | {{ end -}}
|
31 | 40 | {{ end -}}
|
32 | 41 | {{ end -}}
|
33 | 42 |
|
34 |
| - |
35 | 43 | {{/* General link-render processing */ -}}
|
36 | 44 |
|
37 |
| -{{ $url := .Destination -}} |
38 | 45 | {{ $isExternal := hasPrefix $url "http" -}}
|
39 | 46 | {{ if $isExternal -}}
|
40 | 47 | {{ if findRE "^https://opentelemetry.io/\\w" $url -}}
|
|
61 | 68 | >
|
62 | 69 | {{- .Text | safeHTML -}}
|
63 | 70 | </a>
|
64 |
| -{{- /* This comment ensures that all trailing whitespace is trimmed. */ -}} |
| 71 | + |
| 72 | +{{- /* |
| 73 | + cSpell:ignore warnf |
| 74 | + This comment ensures that all trailing whitespace is trimmed. |
| 75 | +*/ -}} |
0 commit comments