new hugo shortcodes to generate docs tabs

Signed-off-by: Pete Lumbis <pete@upbound.io>
This commit is contained in:
Pete Lumbis 2022-09-13 17:42:06 -04:00
parent f81e633169
commit f0b844802c
No known key found for this signature in database
GPG Key ID: FDC6C20960060000
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,13 @@
{{ if .Parent }}
{{ $tab_name := .Get 0 }}
{{ $group := printf "tabs-%s" (.Parent.Get 0) }}
{{ if not (.Parent.Scratch.Get $group) }}
{{ .Parent.Scratch.Set $group slice }}
{{ end }}
{{ .Parent.Scratch.Add $group (dict "Name" $tab_name "Content" (.Inner | htmlUnescape | safeHTML) ) }}
{{ else }}
{{ errorf "%q: 'tab' shortcode must be inside 'tabs' shortcode" .Page.File.Path }}
{{ end }}

View File

@ -0,0 +1,25 @@
{{- if .Inner -}}{{ end -}}
{{- $id := .Get 0 -}}
{{- $group := printf "tabs-%s" $id -}}
<ul class="nav nav-tabs">
{{- range $index, $tab := .Scratch.Get $group -}}
{{- $expand := true -}}
{{- if $index -}}
{{- $expand := false -}}
{{- end -}}
<li class="{{ if not $index -}}active{{end}}">
<a href="#{{$tab.Name | anchorize}}" data-toggle="tab" aria-expanded="{{$expand}}">{{$tab.Name}}</a>
</li>
{{- end -}}
</ul>
<br />
<div class="tab-content">
{{- range $index, $tab := .Scratch.Get $group -}}
<div class="tab-pane fade {{ if not $index}}active in{{end}}" id="{{$tab.Name | anchorize}}">
{{- .Content | safeHTML | $.Page.RenderString -}}
</div>
{{- end -}}
</div>
<p><br /></p>