Skip to content

Commit b03a0f5

Browse files
committed
details: support built-in Hugo shortcode #957
1 parent 39fcbb3 commit b03a0f5

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

layouts/partials/shortcodes/notice.html

+27-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,35 @@
3232
{{- $expander = true }}
3333
{{- end }}
3434
{{- end }}
35+
{{- $params := .params | default dict }}
36+
{{- $classes := split (index $params "class" | default "") " " }}
37+
{{- $classes = $classes | append "box" }}
38+
{{- $classes = $classes | append "cstyle" }}
39+
{{- $classes = $classes | append $class }}
40+
{{- $classes = $classes | append $style }}
41+
{{- if $expander }}
42+
{{- $classes = $classes | append "expand" }}
43+
{{- else }}
44+
{{- $expanded = true }}
45+
{{- end }}
46+
{{- $params = dict "class" (delimit $classes " ") | merge $params }}
47+
{{- if $color }}
48+
{{- $styles := split (index $params "style" | default "") ";" }}
49+
{{- $styles = $styles | append "--VARIABLE-BOX-color: {{ $color }}" }}
50+
{{- $params = dict "style" (delimit $styles ";") | merge $params }}
51+
{{- end }}
52+
{{ if $groupid }}
53+
{{- $params = dict "name" $groupid | merge $params }}
54+
{{- end }}
3555
{{- with $page }}
3656
{{- if or $icon $title $hasContent -}}
37-
<details class="{{ if $expander }}expand {{ end }}box {{ $class }} cstyle {{ $style }}"{{ if $color }} style=" --VARIABLE-BOX-color: {{ $color }};"{{ end }}{{ if $groupid }} name="{{ $groupid }}" {{ end }}{{ if not $expander }} tabindex="-1" open{{ else if $expanded }} open{{ end }}>
57+
<details
58+
{{- if $expanded }} open{{ end }}
59+
{{- range $k, $v := $params }}
60+
{{- if not (or (in (slice "open" "summary") $k) (strings.HasPrefix $k "on")) }}
61+
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
62+
{{- end }}
63+
{{- end }}>
3864
<summary class="box-label{{ if and (not $expander) (not $icon) (not $title) }} a11y-only{{ end }}">{{ if $expander }}
3965
<i class="expander-icon fa-fw fas fa-chevron-right"></i> {{ end }}{{ if $icon }}
4066
<i class="{{ $icon }}"></i> {{ end }}{{ if $title }}

layouts/partials/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.1.1+62b52bb8680225e7de2ff0442813709ae1e14bc0
1+
7.1.1+39fcbb328323656eda3acf6911adb446bd439fe5

layouts/shortcodes/details.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- $summary := (.Get "summary") | default (T "Details") }}
2+
{{- $open := false }}
3+
{{- if in (slice "false" false 0) (.Get "open") }}
4+
{{- $open = false }}
5+
{{- else if in (slice "true" true 1) (.Get "open")}}
6+
{{- $open = true }}
7+
{{- end }}
8+
{{- partial "shortcodes/notice.html" (dict
9+
"page" .Page
10+
"content" .Inner
11+
"expanded" $open
12+
"params" .Params
13+
"style" "transparent"
14+
"title" $summary
15+
) }}

0 commit comments

Comments
 (0)