Skip to content

Commit

Permalink
Rewrite tabs shortcode to make them simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-shpak committed Oct 8, 2024
1 parent 1bda9fb commit f8a0e89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
21 changes: 9 additions & 12 deletions layouts/shortcodes/tab.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{{ if .Parent }}
{{ $name := .Get 0 }}
{{ $group := printf "tabs-%d" .Parent.Ordinal }}

{{ if not (.Parent.Scratch.Get $group) }}
{{ .Parent.Scratch.Set $group slice }}
{{ end }}

{{ .Parent.Scratch.Add $group (dict "Name" $name "Content" .Inner) }}
{{ else }}
{{ errorf "%q: 'tab' shortcode must be inside 'tabs' shortcode" .Page.Path }}
{{ end}}
{{- $group := printf "tabs-%d" .Parent.Ordinal -}}
{{- $tab := printf "%s-%d" $group .Ordinal }}
<input type="radio" class="toggle" name="{{ $group }}" id="{{ $tab }}" {{ if not .Ordinal }}checked="checked"{{ end }} />
<label for="{{ $tab }}">
{{- .Get 0 -}}
</label>
<div class="book-tabs-content markdown-inner">
{{- .Inner -}}
</div>
13 changes: 1 addition & 12 deletions layouts/shortcodes/tabs.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
{{- if .Inner }}{{ end -}}
{{- $group := printf "tabs-%d" .Ordinal -}}

<div class="book-tabs">
{{- range $index, $tab := .Scratch.Get $group -}}
<input type="radio" class="toggle" name="{{ $group }}" id="{{ printf "%s-%d" $group $index }}" {{ if not $index }}checked="checked"{{ end }} />
<label for="{{ printf "%s-%d" $group $index }}">
{{- $tab.Name -}}
</label>
<div class="book-tabs-content markdown-inner">
{{- .Content | safeHTML -}}
</div>
{{- end -}}
{{ .Inner }}
</div>

0 comments on commit f8a0e89

Please sign in to comment.