Merge pull request #46706 from mariasalcedo/fix/glossary-definition

fix(shortcode): Amend glossary definition shortcode
This commit is contained in:
Kubernetes Prow Robot 2024-11-25 00:44:55 +00:00 committed by GitHub
commit d7be80735f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 8 deletions

View File

@ -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)<p>.*?</p>" . 1) 0 -}}
{{- $firstPara := index (findRE "(?s)<p>.*?</p>" .Content 1) 0 -}}
{{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}}
{{- $first := slicestr $firstPara 0 1 | lower -}}
{{- if $prepend -}}
@ -28,13 +25,15 @@
{{- end -}}
{{- else -}}
{{- if $prepend -}}
{{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}}
{{- $firstPara := index (findRE "(?s)<p>.*?</p>" .Content 1) 0 -}}
{{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}}
{{- $first := slicestr $firstPara 0 1 | lower -}}
{{- $prepended := printf "<p>%s %s%s</p>" $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 -}}