Skip to content

Commit f6ffc7c

Browse files
authored
Merge pull request #23028 from sftim/20200808_fix_glossary_definition_shortcode
Fix glossary definition shortcode
2 parents 70b75e1 + c105f1a commit f6ffc7c

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

content/en/docs/contribute/style/hugo-shortcodes/index.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,39 @@ Renders to:
9090

9191
## Glossary
9292

93+
There are two glossary tooltips.
94+
9395
You can reference glossary terms with an inclusion that automatically updates and replaces content with the relevant links from [our glossary](/docs/reference/glossary/). When the term is moused-over by someone
9496
using the online documentation, the glossary entry displays a tooltip.
9597

98+
As well as inclusions with tooltips, you can reuse the definitions from the glossary in
99+
page content.
100+
96101
The raw data for glossary terms is stored at [https://github.com/kubernetes/website/tree/master/content/en/docs/reference/glossary](https://github.com/kubernetes/website/tree/master/content/en/docs/reference/glossary), with a content file for each glossary term.
97102

98-
### Glossary Demo
103+
### Glossary demo
99104

100105
For example, the following include within the markdown renders to {{< glossary_tooltip text="cluster" term_id="cluster" >}} with a tooltip:
101106

102-
```liquid
107+
```
103108
{{</* glossary_tooltip text="cluster" term_id="cluster" */>}}
104109
```
105110

111+
Here's a short glossary definition:
112+
113+
```
114+
{{</* glossary_definition prepend="A cluster is" term_id="cluster" length="short" */>}}
115+
```
116+
which renders as:
117+
{{< glossary_definition prepend="A cluster is" term_id="cluster" length="short" >}}
118+
119+
You can also include a full definition:
120+
```
121+
{{</* glossary_definition term_id="cluster" length="all" */>}}
122+
```
123+
which renders as:
124+
{{< glossary_definition term_id="cluster" length="all" >}}
125+
106126
## Table captions
107127

108128
You can make tables more accessible to screen readers by adding a table caption. To add a [caption](https://www.w3schools.com/tags/tag_caption.asp) to a table, enclose the table with a `table` shortcode and specify the caption with the `caption` parameter.
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1-
21
{{- $id := .Get "term_id" -}}
32
{{- $length := .Get "length" -}}
4-
{{- $prepend := .Get "prepend" }}
3+
{{- $prepend := .Get "prepend" -}}
54
{{- $glossaryBundle := site.GetPage "page" "docs/reference/glossary" -}}
65
{{- $glossaryItems := $glossaryBundle.Resources.ByType "page" -}}
76
{{- $term_info := $glossaryItems.GetMatch (printf "%s.md" $id ) -}}
7+
{{- $showFullDefinition := false -}}
88
{{- if not $term_info -}}
9-
{{- 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 -}}
10-
{{- end -}}
11-
{{- with $term_info -}}
12-
{{- if (strings.Contains "short" $length) -}}
13-
{{- with .Summary -}}
14-
{{- if $prepend }}{{- replace . "<p>" (printf "<P>%s %s" $prepend .) -}}{{ else }}{{- . -}}{{ end -}}
15-
{{- else -}}
16-
{{- partial "templates/errorthrower.html" (dict "block" "summary" "purpose" .purpose "describes the key term in greater depth, supplementing the short_description") . -}}
17-
{{- end -}}
18-
{{- end -}}
19-
{{- if (strings.Contains "all|long" $length) -}}
20-
{{- with .Content -}}
21-
{{- if $prepend }}
22-
{{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}}
23-
{{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}}
24-
{{- $first := slicestr $firstPara 0 1 | lower }}
25-
{{- $prepended := printf "<p>%s %s%s</p>" $prepend $first (slicestr $firstPara 1) -}}
26-
{{- replace . $firstPara $prepended | safeHTML -}}{{ else }}{{- . -}}{{ end -}}
9+
{{- 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 -}}
2710
{{- end -}}
11+
{{- if or (eq "long" $length) (eq "all" $length) -}}
12+
{{- $showFullDefinition = true -}}
13+
{{- else if (eq "short" $length) -}}
14+
{{- $showFullDefinition = false -}}
15+
{{- else -}}
16+
{{- errorf "[%s] %q: invalid glossary definition length %q" site.Language.Lang .Page.Path $length -}}
2817
{{- end -}}
18+
{{- with $term_info.Content -}}
19+
{{- if not $showFullDefinition -}}
20+
{{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}}
21+
{{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}}
22+
{{- $first := slicestr $firstPara 0 1 | lower -}}
23+
{{- if $prepend -}}
24+
{{- $prepended := printf "<p>%s %s%s</p>" $prepend $first (slicestr $firstPara 1) -}}
25+
{{- $prepended | safeHTML -}}
26+
{{- else -}}
27+
{{- $firstPara | safeHTML -}}
28+
{{- end -}}
29+
{{- else -}}
30+
{{- if $prepend -}}
31+
{{- $firstPara := index (findRE "(?s)<p>.*?</p>" . 1) 0 -}}
32+
{{- $firstPara := $firstPara | strings.TrimSuffix "</p>" | strings.TrimPrefix "<p>" -}}
33+
{{- $first := slicestr $firstPara 0 1 | lower -}}
34+
{{- $prepended := printf "<p>%s %s%s</p>" $prepend $first (slicestr $firstPara 1) -}}
35+
{{- replace . $firstPara $prepended | safeHTML -}}
36+
{{- else -}}
37+
{{- . -}}
38+
{{- end -}}
39+
{{- end -}}
2940
{{- end -}}

0 commit comments

Comments
 (0)