Merge pull request #2764 from alxhslm/accordian

 Feat: Add accordian shortcode
This commit is contained in:
Nuno C.
2026-02-03 00:04:54 +00:00
committed by GitHub
3 changed files with 163 additions and 0 deletions
@@ -96,6 +96,92 @@ The alert sign (`+` or `-`) is optional to control whether the admonition is fol
> [!INFO]- Customize admonition
> See the [admonition customization guide](https://github.com/nunocoracao/blowfish/blob/main/layouts/_default/_markup/render-blockquote.html).
## Accordion
`accordion` creates a collapsible set of panels. Use the `accordionItem` sub-shortcode to define each item. You can control whether multiple items can be open at the same time using the `mode` parameter.
<!-- prettier-ignore-start -->
| Parameter | Description |
| --------- | ------------------------------------------------------------------------------------------------- |
| `mode` | **Optional.** `collapse` (single open) or `open` (multiple open). Defaults to `collapse`. |
| `separated` | **Optional.** `true` to show each item as a separate card. Defaults to `false` (joined list). |
<!-- prettier-ignore-end -->
`accordionItem` parameters:
<!-- prettier-ignore-start -->
| Parameter | Description |
| --------- | --------------------------------------------------------------------------------------------------- |
| `title` | **Required.** Title shown in the item header. |
| `open` | **Optional.** Set to `true` to have the item open by default. |
| `header` | **Optional.** Alias for `title`, kept for compatibility with other shortcodes. |
<!-- prettier-ignore-end -->
**Example 1: `mode="open"` (multiple items can be open) + `separated=true`**
```md
{{</* accordion mode="open" separated=true */>}}
{{</* accordionItem title="Markdown example" open=true */>}}
This item demonstrates Markdown rendering:
- **Bold text**
- Lists
- `inline code`
{{</* /accordionItem */>}}
{{</* accordionItem title="Shortcode example" md=false */>}}
This item demonstrates shortcode rendering with <code>md=false</code>:
{{</* alert */>}}This is an inline alert.{{</* /alert */>}}
{{</* /accordionItem */>}}
{{</* /accordion */>}}
```
{{< accordion mode="open" separated=true >}}
{{< accordionItem title="Markdown example" open=true >}}
This item demonstrates Markdown rendering:
- **Bold text**
- Lists
- `inline code`
{{< /accordionItem >}}
{{< accordionItem title="Shortcode example" md=false >}}
This item demonstrates shortcode rendering with <code>md=false</code>:
{{< alert >}}This is an inline alert.{{< /alert >}}
{{< /accordionItem >}}
{{< /accordion >}}
**Example 2: `mode="collapse"` (only one item open at a time)**
```md
{{</* accordion mode="collapse" */>}}
{{</* accordionItem title="First item" open=true */>}}
This item uses Markdown with a short list:
1. One
2. Two
3. Three
{{</* /accordionItem */>}}
{{</* accordionItem title="Second item" md=false */>}}
This item includes another shortcode:
{{</* badge */>}}Tip{{</* /badge */>}}
{{</* /accordionItem */>}}
{{</* /accordion */>}}
```
{{< accordion mode="collapse" >}}
{{< accordionItem title="First item" open=true >}}
This item uses Markdown with a short list:
1. One
2. Two
3. Three
{{< /accordionItem >}}
{{< accordionItem title="Second item" md=false >}}
This item includes another shortcode:
{{< badge >}}Tip{{< /badge >}}
{{< /accordionItem >}}
{{< /accordion >}}
<br/><br/><br/>
+46
View File
@@ -0,0 +1,46 @@
{{ $id := delimit (slice "accordion" (partial "functions/uid.html" .)) "-" }}
{{ $mode := .Get "mode" | default "collapse" }}
{{ $separated := .Get "separated" | default false }}
{{ $isSeparated := or (eq $separated true) (eq $separated "true") }}
<div
id="{{ $id }}"
class="{{ if $isSeparated }}space-y-2{{ else }}border border-neutral-200 dark:border-neutral-700 rounded-lg overflow-hidden{{ end }}"
data-accordion="{{ $mode }}"
data-accordion-separated="{{ $isSeparated }}"
>
{{- .Inner -}}
</div>
{{ if $isSeparated }}
<style>
#{{ $id }} > details + details {
margin-top: 0.5rem;
}
</style>
{{ else }}
<style>
#{{ $id }} > details + details {
border-top: 1px solid rgb(var(--color-neutral-200));
}
.dark #{{ $id }} > details + details {
border-top-color: rgb(var(--color-neutral-700));
}
</style>
{{ end }}
{{ if eq $mode "collapse" }}
<script>
(() => {
const root = document.getElementById("{{ $id }}");
if (!root) return;
const items = root.querySelectorAll("details[data-accordion-item]");
items.forEach((item) => {
item.addEventListener("toggle", () => {
if (!item.open) return;
items.forEach((other) => {
if (other !== item) other.removeAttribute("open");
});
});
});
})();
</script>
{{ end }}
+31
View File
@@ -0,0 +1,31 @@
{{ $parent := .Parent }}
{{ $separated := false }}
{{ if $parent }}
{{ $separated = $parent.Get "separated" | default false }}
{{ end }}
{{ $isSeparated := or (eq $separated true) (eq $separated "true") }}
{{ $title := .Get "title" | default (.Get "header") }}
{{ $md := .Get "md" | default true }}
{{ $open := .Get "open" | default false }}
{{ $isOpen := or (eq $open true) (eq $open "true") }}
<details
class="{{ if $isSeparated }}rounded-lg border border-neutral-200 dark:border-neutral-700 overflow-hidden{{ else }}border-none{{ end }}"
data-accordion-item
{{ if $isOpen }}open{{ end }}
>
<summary class="flex w-full cursor-pointer items-center justify-between gap-4 px-4 py-3 text-left text-lg font-semibold text-neutral-900 dark:text-neutral-100">
<span>{{ $title }}</span>
<span>
{{ partial "icon" "chevron-down" }}
</span>
</summary>
<div class="px-4 pb-4 text-neutral-700 dark:text-neutral-300">
{{ if $md }}
{{- .Inner | markdownify -}}
{{ else }}
{{- .Inner -}}
{{ end }}
</div>
</details>