mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -2,54 +2,52 @@
|
||||
Renders the glossary of terms.
|
||||
|
||||
When you call this shortcode using the {{% %}} notation, the glossary terms are
|
||||
Markdown headings (level 6) which means they are members of .Page.Fragments.
|
||||
This allows the link render hook to verify links to glossary terms.
|
||||
Markdown headings (level 6) which means they are members of .Fragments. This
|
||||
allows the link render hook to verify links to glossary terms.
|
||||
|
||||
Yes, the terms themselves are pages, but we don't want to link to the pages, at
|
||||
least not right now. Instead, we want to link to the fragments rendered by this
|
||||
least not right now. Instead, we want to link to the ids rendered by this
|
||||
shortcode.
|
||||
|
||||
@returns {template.HTML}
|
||||
|
||||
@example {{% glossary %}}
|
||||
*/}}
|
||||
*/ -}}
|
||||
{{- $path := "/quick-reference/glossary" }}
|
||||
{{- with site.GetPage $path }}
|
||||
|
||||
{{- /* Build and render alphabetical index. */}}
|
||||
{{- $m := dict }}
|
||||
{{- range $p := .Pages.ByTitle }}
|
||||
{{- $k := substr .Title 0 1 | strings.ToUpper }}
|
||||
{{- if index $m $k }}
|
||||
{{- continue }}
|
||||
{{- end }}
|
||||
{{- $anchor := path.BaseName .Path | anchorize }}
|
||||
{{- $m = merge $m (dict $k $anchor) }}
|
||||
{{- /* Build and render alphabetical index. */}}
|
||||
{{- $m := dict }}
|
||||
{{- range $p := .Pages.ByTitle }}
|
||||
{{- $k := substr .Title 0 1 | strings.ToUpper }}
|
||||
{{- if index $m $k }}
|
||||
{{- continue }}
|
||||
{{- end }}
|
||||
{{- range $k, $v := $m }}
|
||||
{{- $anchor := path.BaseName .Path | anchorize }}
|
||||
{{- $m = merge $m (dict $k $anchor) }}
|
||||
{{- end }}
|
||||
{{- range $k, $v := $m }}
|
||||
[{{ $k }}](#{{ $v }}) {{/* Do not indent. */}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* Render glossary terms. */}}
|
||||
{{- range $p := .Pages.ByTitle }}
|
||||
###### {{ .Title }}{{/* Do not indent. */}}
|
||||
{{ .RenderShortcodes }}{{/* Do not indent. */}}
|
||||
{{- with .Params.reference }}
|
||||
{{- $destination := "" }}
|
||||
{{- with $u := urls.Parse . }}
|
||||
{{- if $u.IsAbs }}
|
||||
{{- $destination = $u.String }}
|
||||
{{/* Render glossary terms. */}}
|
||||
{{- range $p := .Pages.ByTitle }}
|
||||
{{ .Title }}{{/* Do not indent. */}}
|
||||
: {{ .RawContent | strings.TrimSpace | safeHTML }}{{/* Do not indent. */}}
|
||||
{{ with .Params.reference }}
|
||||
{{- $destination := "" }}
|
||||
{{- with $u := urls.Parse . }}
|
||||
{{- if $u.IsAbs }}
|
||||
{{- $destination = $u.String }}
|
||||
{{- else }}
|
||||
{{- with site.GetPage $u.Path }}
|
||||
{{- $destination = .RelPermalink }}
|
||||
{{- else }}
|
||||
{{- with site.GetPage $u.Path -}}
|
||||
{{- $destination = .RelPermalink }}
|
||||
{{- else }}
|
||||
{{- errorf "The %q shortcode was unable to find the reference link %s: see %s" $.Name . $p.String }}
|
||||
{{- end }}
|
||||
{{- errorf "The %q shortcode was unable to find the reference link %s: see %s" $.Name . $p.String }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
 See [details]({{ $destination }}).{{/* Do not indent. */}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
: See [details]({{ $destination }}).{{/* Do not indent. */}}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
|
||||
{{- else }}
|
||||
{{- errorf "The %q shortcode was unable to get %s: see %s" .Name $path .Position}}
|
||||
|
Reference in New Issue
Block a user