details: support built-in Hugo shortcode #957

This commit is contained in:
Sören Weber 2024-12-01 22:17:19 +01:00
parent 39fcbb3283
commit b03a0f508a
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 43 additions and 2 deletions

View file

@ -32,9 +32,35 @@
{{- $expander = true }}
{{- end }}
{{- end }}
{{- $params := .params | default dict }}
{{- $classes := split (index $params "class" | default "") " " }}
{{- $classes = $classes | append "box" }}
{{- $classes = $classes | append "cstyle" }}
{{- $classes = $classes | append $class }}
{{- $classes = $classes | append $style }}
{{- if $expander }}
{{- $classes = $classes | append "expand" }}
{{- else }}
{{- $expanded = true }}
{{- end }}
{{- $params = dict "class" (delimit $classes " ") | merge $params }}
{{- if $color }}
{{- $styles := split (index $params "style" | default "") ";" }}
{{- $styles = $styles | append "--VARIABLE-BOX-color: {{ $color }}" }}
{{- $params = dict "style" (delimit $styles ";") | merge $params }}
{{- end }}
{{ if $groupid }}
{{- $params = dict "name" $groupid | merge $params }}
{{- end }}
{{- with $page }}
{{- if or $icon $title $hasContent -}}
<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 }}>
<details
{{- if $expanded }} open{{ end }}
{{- range $k, $v := $params }}
{{- if not (or (in (slice "open" "summary") $k) (strings.HasPrefix $k "on")) }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end }}>
<summary class="box-label{{ if and (not $expander) (not $icon) (not $title) }} a11y-only{{ end }}">{{ if $expander }}
<i class="expander-icon fa-fw fas fa-chevron-right"></i> {{ end }}{{ if $icon }}
<i class="{{ $icon }}"></i> {{ end }}{{ if $title }}

View file

@ -1 +1 @@
7.1.1+62b52bb8680225e7de2ff0442813709ae1e14bc0
7.1.1+39fcbb328323656eda3acf6911adb446bd439fe5

View file

@ -0,0 +1,15 @@
{{- $summary := (.Get "summary") | default (T "Details") }}
{{- $open := false }}
{{- if in (slice "false" false 0) (.Get "open") }}
{{- $open = false }}
{{- else if in (slice "true" true 1) (.Get "open")}}
{{- $open = true }}
{{- end }}
{{- partial "shortcodes/notice.html" (dict
"page" .Page
"content" .Inner
"expanded" $open
"params" .Params
"style" "transparent"
"title" $summary
) }}