From ef0fe96557f9a63deb37fa0cb846f26a80d5db21 Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Sat, 12 Aug 2023 16:08:23 +0800 Subject: [PATCH] feat: add the accordion shortcode (#58) --- layouts/partials/bootstrap/accordion.html | 60 +++++++++++++++++++++ layouts/shortcodes/bootstrap/accordion.html | 1 + layouts/shortcodes/bs/accordion.html | 1 + 3 files changed, 62 insertions(+) create mode 100644 layouts/partials/bootstrap/accordion.html create mode 100644 layouts/shortcodes/bootstrap/accordion.html create mode 100644 layouts/shortcodes/bs/accordion.html diff --git a/layouts/partials/bootstrap/accordion.html b/layouts/partials/bootstrap/accordion.html new file mode 100644 index 0000000..599e3cc --- /dev/null +++ b/layouts/partials/bootstrap/accordion.html @@ -0,0 +1,60 @@ +{{- $data := "" }} +{{- $flush := false }} +{{- $alwaysOpen := false }} +{{- if .IsNamedParams }} + {{- $data = .Get "data" }} + {{- if isset .Params "flush" }}{{ $flush = .Get "flush" }}{{ end }} + {{- if isset .Params "alwaysOpen" }} + {{- $alwaysOpen = .Get "alwaysOpen" }} + {{- end }} +{{- else }} + {{- $data = .Get 0 }} +{{- end }} +{{- $items := slice }} +{{- $items := site.Data }} +{{- range split $data "." }} + {{- with index $items . }} + {{- $items = . }} + {{- else }} + {{- $items = false }} + {{- break }} + {{- end }} +{{- end }} +{{- if not $data }} + {{- warnf `[bootstrap][accordion] the data name is required.` }} +{{- else if eq $items false }} + {{- warnf `[bootstrap][accordion] the data file is missing: %s.` $data }} +{{- else }} + {{- $id := printf "accordion-%d-%s" .Ordinal $data }} +
+ {{- $first := true }} + {{- range $name, $item := sort $items "weight" }} + {{- $show := cond (isset . "show") .show $first }} + {{- $itemID := printf "%s-%d" $id $name }} +
+

+ +

+
+
+ {{ .content | markdownify }} +
+
+
+ {{- $first = false }} + {{- end }} +
+{{- end }} diff --git a/layouts/shortcodes/bootstrap/accordion.html b/layouts/shortcodes/bootstrap/accordion.html new file mode 100644 index 0000000..a40d2a9 --- /dev/null +++ b/layouts/shortcodes/bootstrap/accordion.html @@ -0,0 +1 @@ +{{ partial "bootstrap/accordion" . }} diff --git a/layouts/shortcodes/bs/accordion.html b/layouts/shortcodes/bs/accordion.html new file mode 100644 index 0000000..a40d2a9 --- /dev/null +++ b/layouts/shortcodes/bs/accordion.html @@ -0,0 +1 @@ +{{ partial "bootstrap/accordion" . }}