Skip to content

Commit fe5f41f

Browse files
committed
#803, use page-level IDs for shortcodes
1 parent 54f9cee commit fe5f41f

7 files changed

Lines changed: 20 additions & 11 deletions

File tree

exampleSite/content.en/docs/shortcodes/experimental/images.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ Enhanced image display with click-to-expand behavior.
1010

1111
## Example
1212

13-
{{< image src="placeholder.svg" alt="Placeholder image" title="Click to expand" loading="lazy" >}}
13+
{{% columns %}}
14+
- {{< image src="placeholder.svg" alt="Placeholder image" title="Click to expand" loading="lazy" >}}
15+
- {{< image src="placeholder.svg" alt="Placeholder image" title="Click to expand" loading="lazy" >}}
16+
{{% /columns %}}
1417

1518
## Parameters
1619

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{- $key := printf "book-%s-id" .Name }}
2+
{{- .Page.Store.Add $key 1 -}}
3+
{{- return .Page.Store.Get $key -}}

layouts/_shortcodes/asciinema.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
<script defer src="{{ "asciinema/asciinema-auto.js" | relURL }}"></script>
88
{{- .Page.Store.Set "asciinema" true -}}
99
{{- end -}}
10+
{{- $id := partial "docs/text/shortcode-id" . -}}
1011
{{- $href := (partial "docs/links/portable-image" (dict "Page" .Page "Destination" (.Get "cast"))) -}}
1112
{{- .Store.Set "asciinema" .Params -}}
1213
{{- .Store.DeleteInMap "asciinema" "cast" -}}
1314
{{- $attributes := partial "docs/text/mapper" (dict
1415
"attributes" (dict)
1516
"set" (dict
16-
"id" (printf "asciinema-%d" .Ordinal)
17+
"id" (printf "asciinema-%d" ($id))
1718
"x-data-cast" $href
1819
"x-data-opts" (.Store.Get "asciinema" | jsonify)
1920
)

layouts/_shortcodes/columns.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{{- $ratio := (split (.Get "ratio") ":") -}}
2+
{{- $id := partial "docs/text/shortcode-id" . -}}
23
{{- if strings.Contains .InnerDeindent "<--->" -}}
34
{{- warnf "{{<columns>}} shortcode separator '<--->' is deprecated, use markdown list instead." -}}
45
{{- $attributes := partial "docs/text/mapper" (dict
56
"attributes" (cond .IsNamedParams .Params dict)
67
"merge" (dict
78
"class" (slice "book-columns" "flex" "flex-wrap")
8-
"id" (printf "book-columns-%d" .Ordinal)
9+
"id" (printf "book-columns-%d" $id)
910
)
1011
) -}}
1112
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
@@ -19,7 +20,7 @@
1920
{{- else -}}
2021
{{- if .Get "ratio" -}}
2122
<style>{{- range $index, $grow := $ratio -}}
22-
#book-columns-{{ $.Ordinal }}>ul>li:nth-child({{ $index | add 1 }}) {
23+
#book-columns-{{ $id }}>ul>li:nth-child({{ $index | add 1 }}) {
2324
flex-grow: {{ default 1 $grow }};
2425
}
2526
{{ end -}}
@@ -29,7 +30,7 @@
2930
"attributes" (cond .IsNamedParams .Params dict)
3031
"merge" (dict
3132
"class" (slice "book-columns")
32-
"id" (printf "book-columns-%d" .Ordinal)
33+
"id" (printf "book-columns-%d" $id)
3334
)
3435
) -}}
3536
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>

layouts/_shortcodes/image.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"attributes" (cond .IsNamedParams .Params dict)
44
"keep" (slice "id" "class" "tabindex" "alt" "title" "loading")
55
) -}}
6-
<label class="book-image" for="book-image-toggle-{{ .Ordinal }}">
7-
<input class="hidden toggle" type="checkbox" id="book-image-toggle-{{ .Ordinal }}" />
8-
<img src="{{ $destination | safeURL }}" {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }} />
9-
</label>
10-
{{- /* remove whitespaces */ -}}
6+
{{- $id := partial "docs/text/shortcode-id" . -}}
7+
<label class="book-image" for="book-image-toggle-{{ $id }}">{{- /* remove whitespaces */ -}}
8+
<input class="hidden toggle" type="checkbox" id="book-image-toggle-{{ $id }}" />{{- /* remove whitespaces */ -}}
9+
<img src="{{ $destination | safeURL }}" {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }} />{{- /* remove whitespaces */ -}}
10+
</label>{{- /* remove whitespaces */ -}}

layouts/_shortcodes/tab.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- $group := printf "tabs-%v" .Parent.Ordinal -}}
1+
{{- $group := printf "tabs-%v" (.Parent.Store.Get "id") -}}
22
{{- $tab := printf "%s-%d" $group .Ordinal -}}
33
<input type="radio" class="toggle" name="{{ $group }}" id="{{ $tab }}" {{ if not .Ordinal }}checked="checked"{{ end }} />
44
{{- /* remove whitespaces */ -}}

layouts/_shortcodes/tabs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- .Store.Set "id" (partial "docs/text/shortcode-id" .) -}}
12
{{- $attributes := partial "docs/text/mapper" (dict
23
"attributes" (cond .IsNamedParams .Params dict)
34
"merge" (dict

0 commit comments

Comments
 (0)