| 1 |
{{/* gotmplfmt-ignore-all */ -}} |
| 2 |
|
| 3 |
{{/* |
| 4 |
Renders the glossary of terms. |
| 5 |
|
| 6 |
When you call this shortcode using the {{% %}} notation, the glossary terms are |
| 7 |
description term (dt) elements which means they are members of .Fragments. This |
| 8 |
allows the link render hook to verify links to glossary terms. |
| 9 |
|
| 10 |
Yes, the terms themselves are pages, but we don't want to link to the pages, at |
| 11 |
least not right now. Instead, we want to link to the ids rendered by this |
| 12 |
shortcode. |
| 13 |
|
| 14 |
@example {{% glossary %}} |
| 15 |
*/}} |
| 16 |
|
| 17 |
{{- $path := "/quick-reference/glossary" }} |
| 18 |
{{- with site.GetPage $path }} |
| 19 |
|
| 20 |
{{- /* Build and render alphabetical index. */}} |
| 21 |
{{- $m := dict }} |
| 22 |
{{- range $p := .Pages.ByTitle }} |
| 23 |
{{- $k := substr .Title 0 1 | strings.ToUpper }} |
| 24 |
{{- if index $m $k }} |
| 25 |
{{- continue }} |
| 26 |
{{- end }} |
| 27 |
{{- $anchor := path.BaseName .Path | anchorize }} |
| 28 |
{{- $m = merge $m (dict $k $anchor) }} |
| 29 |
{{- end }} |
| 30 |
{{- range $k, $v := $m }} |
| 31 |
[{{ $k }}](#{{ $v }}) {{/* Do not indent. */}} |
| 32 |
{{- end }} |
| 33 |
|
| 34 |
{{/* Render glossary terms. */}} |
| 35 |
{{- range $p := .Pages.ByTitle }} |
| 36 |
{{ .Title }}{{/* Do not indent. */}} |
| 37 |
: {{ .RawContent | strings.TrimSpace | safeHTML }}{{/* Do not indent. */}} |
| 38 |
{{ with .Params.reference }} |
| 39 |
{{- $destination := "" }} |
| 40 |
{{- with $u := urls.Parse . }} |
| 41 |
{{- if $u.IsAbs }} |
| 42 |
{{- $destination = $u.String }} |
| 43 |
{{- else }} |
| 44 |
{{- with site.GetPage $u.Path }} |
| 45 |
{{- if $u.Fragment }} |
| 46 |
{{- $destination = printf "%s#%s" .Path $u.Fragment }} |
| 47 |
{{ else }} |
| 48 |
{{- $destination = .Path }} |
| 49 |
{{- end }} |
| 50 |
{{- else }} |
| 51 |
{{- errorf "The %q shortcode was unable to find the reference link %s: see %s" $.Name . $p.String }} |
| 52 |
{{- end }} |
| 53 |
{{- end }} |
| 54 |
{{- end }} |
| 55 |
: See [details]({{ $destination }}).{{/* Do not indent. */}} |
| 56 |
{{- end }} |
| 57 |
{{ end }} |
| 58 |
|
| 59 |
{{- else }} |
| 60 |
{{- errorf "The %q shortcode was unable to get %s: see %s" .Name $path .Position }} |
| 61 |
{{- end }} |