hugo-theme-relearn/layouts/partials/shortcodes/notice.html
2024-12-01 22:17:24 +01:00

77 lines
No EOL
3.1 KiB
HTML

{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'notice' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $page.File.Filename }}
{{- end }}
{{- $class := .class | default "notices" }}
{{- $containerstyle := .containerstyle | default "div" }}
{{- $containerclass := .containerclass | default slice | append "box-content" }}
{{- $color := .color | default "" }}
{{- $content := trim .content "\n\r\t " }}
{{- $hasContent := ne (strings.TrimLeft "<p>" $content) "" }}
{{- if not (hasPrefix $content "<") }}
{{- $content = printf "<p>\n%s" $content }}
{{- end }}
{{- $groupid := .groupid }}
{{- $style := .style | default "default" }}
{{- $boxStyle := partial "_relearn/boxStyle.gotmpl" (dict "style" $style "title" .title "icon" .icon) }}
{{- $title := trim ($boxStyle.title) " " }}
{{- $icon := trim ($boxStyle.icon) " " }}
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- $expander := false }}
{{- $expanded := .expanded | default "" }}
{{- if $hasContent }}
{{- if eq (printf "%T" $expanded) "string" }}
{{- if ne (trim $expanded " ") "" }}
{{- $expander = true }}
{{- $expanded = (eq $expanded "true") }}
{{- end }}
{{- else }}
{{- $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
{{- 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 }}
{{ $title | .RenderString }}{{ else }}
<span class="a11y-only">{{ T "Details" }}</span>{{ end }}
</summary>
{{- if $hasContent }}
{{ printf " <%s class=\"%s\">" $containerstyle (delimit $containerclass " ") | safeHTML }}
{{ $content | safeHTML }}
{{ printf " </%s>" $containerstyle | safeHTML }}
{{- end }}
</details>
{{- end }}
{{- end }}