|
3 | 3 | {{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }}
|
4 | 4 | {{ $fileDir := path.Split $file }}
|
5 | 5 | {{ $bundlePath := path.Join .Page.File.Dir $fileDir.Dir }}
|
6 |
| -{{ $filename := printf "/content/%s/examples/%s" .Page.Lang $file | safeURL }} |
7 |
| -{{ $ghlink := printf "https://%s/%s%s" site.Params.githubwebsiteraw (default "main" site.Params.docsbranch) $filename | safeURL }} |
| 6 | +{{ $.Scratch.Set "filename" (printf "/content/%s/examples/%s" .Page.Lang $file) }} |
8 | 7 | {{/* First assume this is a bundle and the file is inside it. */}}
|
9 |
| -{{ $resource := $p.Resources.GetMatch (printf "%s*" $file ) }} |
10 |
| -{{ with $resource }} |
| 8 | +{{ with $p.Resources.GetMatch (printf "%s*" $file) }} |
11 | 9 | {{ $.Scratch.Set "content" .Content }}
|
12 |
| -{{ else }} |
| 10 | +{{ end }} |
13 | 11 | {{/* Read the file relative to the content root. */}}
|
14 |
| -{{ $resource := readFile $filename}} |
15 |
| -{{ with $resource }}{{ $.Scratch.Set "content" . }}{{ end }} |
| 12 | +{{ with readFile ($.Scratch.Get "filename")}} |
| 13 | +{{ $.Scratch.Set "content" . }} |
| 14 | +{{ end }} |
| 15 | +{{/* If not found, try the default language */}} |
| 16 | +{{ $defaultLang := (index (sort site.Languages "Weight") 0).Lang }} |
| 17 | +{{ with readFile (printf "/content/%s/examples/%s" $defaultLang $file) }} |
| 18 | +{{ $.Scratch.Set "content" . }} |
| 19 | +{{ $.Scratch.Set "filename" (printf "/content/%s/examples/%s" $defaultLang $file) }} |
16 | 20 | {{ end }}
|
17 | 21 | {{ if not ($.Scratch.Get "content") }}
|
18 | 22 | {{ errorf "[%s] %q not found in %q" site.Language.Lang $fileDir.File $bundlePath }}
|
19 | 23 | {{ end }}
|
| 24 | +{{ $filename := printf ($.Scratch.Get "filename") | safeURL }} |
| 25 | +{{ $ghlink := printf "https://%s/%s%s" site.Params.githubwebsiteraw (default "main" site.Params.docsbranch) $filename | safeURL }} |
20 | 26 | {{ with $.Scratch.Get "content" }}
|
21 | 27 | <div class="highlight code-sample">
|
22 | 28 | <div class="copy-code-icon">
|
|
0 commit comments