|
1 |
| -{{ $isExternal := hasPrefix .Destination "http" -}} |
| 1 | +{{ $url := .Destination -}} |
| 2 | + |
| 3 | +{{/* |
| 4 | + |
| 5 | + Localization link processing |
| 6 | + |
| 7 | + The following code block will prefix the page language code to an |
| 8 | + absolute path when: |
| 9 | + |
| 10 | + - 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. |
| 15 | + |
| 16 | + */ -}} |
| 17 | + |
| 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) -}} |
| 30 | + {{ end -}} |
| 31 | + {{ end -}} |
| 32 | +{{ end -}} |
| 33 | + |
| 34 | + |
| 35 | +{{/* General link-render processing */ -}} |
| 36 | + |
| 37 | +{{ $url := .Destination -}} |
| 38 | +{{ $isExternal := hasPrefix $url "http" -}} |
2 | 39 | {{ if $isExternal -}}
|
3 |
| - {{ if findRE "^https://opentelemetry.io/\\w" .Destination -}} |
| 40 | + {{ if findRE "^https://opentelemetry.io/\\w" $url -}} |
4 | 41 | {{ warnf "%s: use a local path, not an external URL, for the following reference to a site local page: %s"
|
5 |
| - .Page.File.Path .Destination -}} |
| 42 | + .Page.File.Path $url -}} |
6 | 43 | {{ else if or
|
7 |
| - (findRE "^https://github.com/open-telemetry/opentelemetry-specification/(blob|tree)/main/specification/\\w" .Destination) |
8 |
| - (findRE "^https://github.com/open-telemetry/opentelemetry-proto/(blob|tree)/main/docs/specification" .Destination) |
9 |
| - (findRE "^https://github.com/open-telemetry/semantic-conventions/(blob|tree)/main/docs" .Destination) |
| 44 | + (findRE "^https://github.com/open-telemetry/opentelemetry-specification/(blob|tree)/main/specification/\\w" $url) |
| 45 | + (findRE "^https://github.com/open-telemetry/opentelemetry-proto/(blob|tree)/main/docs/specification" $url) |
| 46 | + (findRE "^https://github.com/open-telemetry/semantic-conventions/(blob|tree)/main/docs" $url) |
10 | 47 | -}}
|
11 | 48 | {{ warnf "%s: use a local path, not an external URL, for the following reference to a local specification page: %s"
|
12 |
| - .Page.File.Path .Destination -}} |
| 49 | + .Page.File.Path $url -}} |
13 | 50 | {{ end -}}
|
14 | 51 | {{ end -}}
|
15 | 52 |
|
16 | 53 | {{/* Until Hugo supports hook params (https://github.com/gohugoio/hugo/issues/6670), we'll inspect .Text. */ -}}
|
17 |
| -{{ $noExternalIcon := in .Text "hk-no-external-icon" -}} |
18 |
| -<a href="{{ .Destination | safeURL }}" |
| 54 | + |
| 55 | +<a href="{{ $url | safeURL }}" |
19 | 56 | {{- with .Title}} title="{{ . }}"{{ end -}}
|
20 | 57 | {{- if $isExternal }} target="_blank" rel="noopener"
|
21 |
| - {{- if not $noExternalIcon }} class="external-link"{{ end -}} |
| 58 | + {{- $noExternalIcon := in .Text "hk-no-external-icon" -}} |
| 59 | + {{ if not $noExternalIcon }} class="external-link"{{ end -}} |
22 | 60 | {{ end -}}
|
23 | 61 | >
|
24 | 62 | {{- .Text | safeHTML -}}
|
|
0 commit comments