Files
FixIt/layouts/_shortcodes/tabs.html
T
Cell fdfd772100 feat(File Tree): add file-tree shortcode support (#685)
* feat(File Tree): add `file-tree` shortcode support

* feat(file-tree): add ignoreList parameter to file-tree shortcode

* feat(file-tree): enhance file-tree shortcode with ignoreList and folderSlash options

* feat(file-tree): enhance file-tree shortcode to support data mode

* feat(file-tree): enhance file-tree shortcode to support file mode

* feat(file-tree): improve content parsing in file-tree shortcode

* feat(file-tree): improve root path validation and error handling in filesystem mode

* test(file-tree): add unit tests for `file-tree` shortcode

* feat(file-tree): add file-tree code block rendering support

* refactor(file-tree): extract filesystem scanning to get-file-tree partial

Move directory traversal and root path validation to a separate partial function,
consolidating all filesystem-related logic in one place. This simplifies the
shortcode implementation and ensures a unified data format for rendering.

* docs(readme): extend code fence and shortcode support for file tree in documentation

* feat(file-tree): add fullRootName parameter for root path display in file tree

* feat(file-tree): add language parameter to get-file-tree function

* feat(file-tree): add highlightList parameter for file-tree shortcode

* perf(file-tree): add level param for get-file-tree function to descend only level directories deep
2026-01-14 16:01:22 +08:00

52 lines
2.2 KiB
HTML

{{- /*
Renders a tabbed interface with multiple tabs and their corresponding content.
See https://fixit.lruihao.cn/documentation/content-management/shortcodes/extended/tabs/
@param {int} [defaultTab=0] - The index of the tab to be active by default (0-based)
@param {string} [type="underline"] - The style type of the tabs ("underline", "pill", "card", "segment", etc.)
@param {string} [placement="top"] - The placement of the tabs ("top", "bottom", "left", "right")
Usage:
{{< tabs defaultTab="1" type="card" placement="top" >}}
{{% tab title="Tab 1" %}}
Content for Tab 1
{{% /tab %}}
{{% tab title="Tab 2" %}}
Content for Tab 2
{{% /tab %}}
{{< /tabs >}}
Note: Tabs must be defined using the nested "tab" shortcode within the "tabs" shortcode.
*/ -}}
{{- $tabs := .Store.Get "tabs" -}}
{{- if not $tabs -}}
{{- errorf "No tabs found. Please add at least one tab to the tabs shortcode. See %s %s" .Name .Position -}}
{{- end -}}
{{- $lenTabs := len $tabs -}}
{{- $defaultTab := .Get "defaultTab" | default 0 -}}
{{- $type := .Get "type" | default "underline" -}}
{{- $placement := .Get "placement" | default "top" -}}
{{- $placementMap := slice "top" "bottom" "left" "right" -}}
{{- if ge $defaultTab $lenTabs -}}
{{- warnf "The defaultTab value %v is out of range [0, %v]. See %s %s" $defaultTab (sub $lenTabs 1) .Name .Position -}}
{{- $defaultTab = 0 -}}
{{- end -}}
{{- if not (in $placementMap $placement) -}}
{{- warnf "The placement value %q is invalid. Supported values are: %v. See %s %s" $placement (delimit $placementMap ", ") .Name .Position -}}
{{- $placement = "top" -}}
{{- end -}}
{{- /* Tabs Container */ -}}
<tab-container default-tab="{{ $defaultTab }}" placement="{{ $placement }}"{{ with $type }} type="{{ . }}"{{ end }}>
{{- range $index, $tab := $tabs -}}
{{- $title := $tab.title | default (printf "Untitled%v" $index) -}}
{{- $id := $tab.id -}}
<button class="tab-button" type="button" role="tab" id="tab-{{ $id }}" aria-selected="{{ eq $index $defaultTab }}">{{ $title | $.Page.RenderString }}</button>
{{- end -}}
{{- .Inner -}}
</tab-container>
{{- .Page.Store.Set "hasTabs" true -}}
{{- if eq hugo.Context.MarkupScope "home" -}}
{{- site.Home.Store.Set "hasTabs" true -}}
{{- end -}}