Skip to content

Commit

Permalink
Merge pull request kubernetes#46706 from mariasalcedo/fix/glossary-de…
Browse files Browse the repository at this point in the history
…finition

fix(shortcode): Amend glossary definition shortcode
  • Loading branch information
k8s-ci-robot authored Nov 25, 2024
2 parents a78d151 + 3144f20 commit d7be807
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions layouts/shortcodes/glossary_definition.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
{{- $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) -}}
{{- $showFullDefinition = false -}}
{{- 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 -}}
Expand All @@ -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 -}}

0 comments on commit d7be807

Please sign in to comment.