|
| 1 | +{{- .Page.Scratch.Add "tabset-counter" 1 -}} |
| 2 | +{{- $tab_set_id := .Get "name" | default (printf "tabset-%s-%d" (.Page.RelPermalink) (.Page.Scratch.Get "tabset-counter") ) | anchorize -}} |
| 3 | +{{- $tabs := .Scratch.Get "tabs" -}} |
| 4 | +{{- if .Inner -}}{{- /* We don't use the inner content, but Hugo will complain if we don't reference it. */ -}}{{- end -}} |
| 5 | +<ul class="nav nav-tabs" id="{{ $tab_set_id }}" role="tablist"> |
| 6 | + {{- range $i, $e := $tabs -}} |
| 7 | + {{- $id := printf "%s-%d" $tab_set_id $i -}} |
| 8 | + {{- if (eq $i 0) -}} |
| 9 | + <li class="nav-item"><a data-toggle="tab" class="nav-link active" href="#{{ $id }}" role="tab" aria-controls="{{ $id }}" aria-selected="true">{{- trim .name " " -}}</a></li> |
| 10 | + {{ else }} |
| 11 | + <li class="nav-item"><a data-toggle="tab" class="nav-link" href="#{{ $id }}" role="tab" aria-controls="{{ $id }}">{{- trim .name " " -}}</a></li> |
| 12 | + {{- end -}} |
| 13 | +{{- end -}} |
| 14 | +</ul> |
| 15 | +<div class="tab-content" id="{{ $tab_set_id }}"> |
| 16 | +{{- range $i, $e := $tabs -}} |
| 17 | +{{- $id := printf "%s-%d" $tab_set_id $i -}} |
| 18 | +{{- if (eq $i 0) -}} |
| 19 | + <div id="{{ $id }}" class="tab-pane show active" role="tabpanel" aria-labelledby="{{ $id }}"> |
| 20 | +{{ else }} |
| 21 | + <div id="{{ $id }}" class="tab-pane" role="tabpanel" aria-labelledby="{{ $id }}"> |
| 22 | +{{ end }} |
| 23 | +<p> |
| 24 | + {{- with .content -}} |
| 25 | + {{- . -}} |
| 26 | + {{- else -}} |
| 27 | + {{- if eq $.Page.BundleType "leaf" -}} |
| 28 | + {{- /* find the file somewhere inside the bundle. Note the use of double asterisk */ -}} |
| 29 | + {{- with $.Page.Resources.GetMatch (printf "**%s*" .include) -}} |
| 30 | + {{- if ne .ResourceType "page" -}} |
| 31 | + {{- /* Assume it is a file that needs code highlighting. */ -}} |
| 32 | + {{- $codelang := $e.codelang | default ( path.Ext .Name | strings.TrimPrefix ".") -}} |
| 33 | + {{- highlight .Content $codelang "" -}} |
| 34 | + {{- else -}} |
| 35 | + {{- .Content -}} |
| 36 | + {{- end -}} |
| 37 | + {{- end -}} |
| 38 | + {{- else -}} |
| 39 | + {{- $path := path.Join $.Page.File.Dir .include -}} |
| 40 | + {{- $page := site.GetPage "page" $path -}} |
| 41 | + {{- with $page -}} |
| 42 | + {{- .Content -}} |
| 43 | + {{- else -}} |
| 44 | + {{- errorf "[%s] tabs include not found for path %q" site.Language.Lang $path -}} |
| 45 | + {{- end -}} |
| 46 | + {{- end -}} |
| 47 | + {{- end -}} |
| 48 | +</div> |
| 49 | +{{- end -}} |
| 50 | +</div> |
0 commit comments