From e188d07af5cc4e98e8e8807add60d8b713313081 Mon Sep 17 00:00:00 2001 From: Maria Salcedo Date: Thu, 6 Jun 2024 18:02:00 +0200 Subject: [PATCH] fix(shortcode): Fix glossary definition shortcode When rendering a index-less glossary definition, it fails with: execute of template failed: template: shortcodes/glossary_definition.html:15:19: executing "shortcodes/glossary_definition.html" at <$term_info.Content>: nil pointer evaluating resource.Resource.Content --- layouts/shortcodes/glossary_definition.html | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/layouts/shortcodes/glossary_definition.html b/layouts/shortcodes/glossary_definition.html index e2c9089747..ee4e3570d6 100644 --- a/layouts/shortcodes/glossary_definition.html +++ b/layouts/shortcodes/glossary_definition.html @@ -5,9 +5,6 @@ {{- $glossaryItems := $glossaryBundle.Resources.ByType "page" -}} {{- $term_info := $glossaryItems.GetMatch (printf "%s.md" $id ) -}} {{- $showFullDefinition := false -}} -{{- if not $term_info -}} - {{- 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 -}} -{{- end -}} {{- if or (eq "long" $length) (eq "all" $length) -}} {{- $showFullDefinition = true -}} {{- else if (eq "short" $length) -}} @@ -15,9 +12,9 @@ {{- else -}} {{- errorf "[%s] %q: invalid glossary definition length %q" site.Language.Lang .Page.Path $length -}} {{- end -}} -{{- with $term_info.Content -}} +{{- with $term_info -}} {{- if not $showFullDefinition -}} - {{- $firstPara := index (findRE "(?s)

.*?

" . 1) 0 -}} + {{- $firstPara := index (findRE "(?s)

.*?

" .Content 1) 0 -}} {{- $firstPara := $firstPara | strings.TrimSuffix "

" | strings.TrimPrefix "

" -}} {{- $first := slicestr $firstPara 0 1 | lower -}} {{- if $prepend -}} @@ -28,13 +25,15 @@ {{- end -}} {{- else -}} {{- if $prepend -}} - {{- $firstPara := index (findRE "(?s)

.*?

" . 1) 0 -}} + {{- $firstPara := index (findRE "(?s)

.*?

" .Content 1) 0 -}} {{- $firstPara := $firstPara | strings.TrimSuffix "

" | strings.TrimPrefix "

" -}} {{- $first := slicestr $firstPara 0 1 | lower -}} {{- $prepended := printf "

%s %s%s

" $prepend $first (slicestr $firstPara 1) -}} - {{- replace . $firstPara $prepended | safeHTML -}} + {{- replace .Content $firstPara $prepended | safeHTML -}} {{- else -}} - {{- . -}} + {{- .Content -}} {{- end -}} {{- end -}} +{{- else -}} + {{- 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 -}} {{- end -}}