|
1 |
| - |
2 | 1 | {{- $id := .Get "term_id" -}}
|
3 | 2 | {{- $length := .Get "length" -}}
|
4 |
| -{{- $prepend := .Get "prepend" }} |
| 3 | +{{- $prepend := .Get "prepend" -}} |
5 | 4 | {{- $glossaryBundle := site.GetPage "page" "docs/reference/glossary" -}}
|
6 | 5 | {{- $glossaryItems := $glossaryBundle.Resources.ByType "page" -}}
|
7 | 6 | {{- $term_info := $glossaryItems.GetMatch (printf "%s.md" $id ) -}}
|
| 7 | +{{- $showFullDefinition := false -}} |
8 | 8 | {{- if not $term_info -}}
|
9 |
| -{{- errorf "[%s] %q: %q is not a valid glossary term_id, see ./docs/reference/glossary/* for a full list" site.Language.Lang .Page.Path $id -}} |
10 |
| -{{- end -}} |
11 |
| -{{- with $term_info -}} |
12 |
| -{{- if (strings.Contains "short" $length) -}} |
13 |
| - {{- with .Summary -}} |
14 |
| - {{- if $prepend }}{{- replace . "<p>" (printf "<P>%s %s" $prepend .) -}}{{ else }}{{- . -}}{{ end -}} |
15 |
| - {{- else -}} |
16 |
| - {{- partial "templates/errorthrower.html" (dict "block" "summary" "purpose" .purpose "describes the key term in greater depth, supplementing the short_description") . -}} |
17 |
| - {{- end -}} |
18 |
| -{{- end -}} |
19 |
| -{{- if (strings.Contains "all|long" $length) -}} |
20 |
| -{{- with .Content -}} |
21 |
| -{{- if $prepend }} |
22 |
| -{{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}} |
23 |
| -{{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}} |
24 |
| -{{- $first := slicestr $firstPara 0 1 | lower }} |
25 |
| -{{- $prepended := printf "<p>%s %s%s</p>" $prepend $first (slicestr $firstPara 1) -}} |
26 |
| -{{- replace . $firstPara $prepended | safeHTML -}}{{ else }}{{- . -}}{{ end -}} |
| 9 | + {{- errorf "[%s] %q: %q is not a valid glossary term_id, see ./docs/reference/glossary/* for a full list" site.Language.Lang .Page.Path $id -}} |
27 | 10 | {{- end -}}
|
| 11 | +{{- if or (eq "long" $length) (eq "all" $length) -}} |
| 12 | + {{- $showFullDefinition = true -}} |
| 13 | +{{- else if (eq "short" $length) -}} |
| 14 | + {{- $showFullDefinition = false -}} |
| 15 | +{{- else -}} |
| 16 | + {{- errorf "[%s] %q: invalid glossary definition length %q" site.Language.Lang .Page.Path $length -}} |
28 | 17 | {{- end -}}
|
| 18 | +{{- with $term_info.Content -}} |
| 19 | + {{- if not $showFullDefinition -}} |
| 20 | + {{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}} |
| 21 | + {{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}} |
| 22 | + {{- $first := slicestr $firstPara 0 1 | lower -}} |
| 23 | + {{- if $prepend -}} |
| 24 | + {{- $prepended := printf "<p>%s %s%s</p>" $prepend $first (slicestr $firstPara 1) -}} |
| 25 | + {{- $prepended | safeHTML -}} |
| 26 | + {{- else -}} |
| 27 | + {{- $firstPara | safeHTML -}} |
| 28 | + {{- end -}} |
| 29 | + {{- else -}} |
| 30 | + {{- if $prepend -}} |
| 31 | + {{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}} |
| 32 | + {{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}} |
| 33 | + {{- $first := slicestr $firstPara 0 1 | lower -}} |
| 34 | + {{- $prepended := printf "<p>%s %s%s</p>" $prepend $first (slicestr $firstPara 1) -}} |
| 35 | + {{- replace . $firstPara $prepended | safeHTML -}} |
| 36 | + {{- else -}} |
| 37 | + {{- . -}} |
| 38 | + {{- end -}} |
| 39 | + {{- end -}} |
29 | 40 | {{- end -}}
|
0 commit comments