update tabs shortcode

This commit is contained in:
Karen Bradshaw
2020-04-27 16:04:40 -04:00
parent de78f4984c
commit 7a98007a29
3 changed files with 200 additions and 146 deletions
+37 -37
View File
@@ -1,43 +1,43 @@
{{ .Page.Scratch.Add "tabset-counter" 1 }}
{{ $tab_set_id := .Get "name" | default (printf "tabset-%s-%d" (.Page.RelPermalink) (.Page.Scratch.Get "tabset-counter") ) | anchorize }}
{{ $tabs := .Scratch.Get "tabs" }}
{{ if .Inner }}{{/* We don't use the inner content, but Hugo will complain if we don't reference it. */}}{{ end }}
{{- .Page.Scratch.Add "tabset-counter" 1 -}}
{{- $tab_set_id := .Get "name" | default (printf "tabset-%s-%d" (.Page.RelPermalink) (.Page.Scratch.Get "tabset-counter") ) | anchorize -}}
{{- $tabs := .Scratch.Get "tabs" -}}
{{- if .Inner -}}{{- /* We don't use the inner content, but Hugo will complain if we don't reference it. */ -}}{{- end -}}
<div id="{{ $tab_set_id }}">
<ul>
{{ range $i, $e := $tabs }}
{{ $id := printf "%s-%d" $tab_set_id $i }}
<li><a href="#{{ $id }}">{{ trim .name " " }}</a></li>
{{ end }}
{{- range $i, $e := $tabs -}}
{{- $id := printf "%s-%d" $tab_set_id $i -}}
<li><a href="#{{ $id }}">{{- trim .name " " -}}</a></li>
{{- end -}}
</ul>
{{ range $i, $e := $tabs }}
{{ $id := printf "%s-%d" $tab_set_id $i }}
{{- range $i, $e := $tabs -}}
{{- $id := printf "%s-%d" $tab_set_id $i -}}
<div id="{{ $id }}">
{{ with .content }}
{{ . }}
{{ else }}
{{ if eq $.Page.BundleType "leaf" }}
{{/* find the file somewhere inside the bundle. Note the use of double asterisk */}}
{{ with $.Page.Resources.GetMatch (printf "**%s*" .include) }}
{{ if ne .ResourceType "page" }}
{{/* Assume it is a file that needs code highlighting. */}}
{{ $codelang := $e.codelang | default ( path.Ext .Name | strings.TrimPrefix ".") }}
{{ highlight .Content $codelang "" }}
{{ else}}
{{ .Content }}
{{ end }}
{{ end }}
{{ else}}
{{ $path := path.Join $.Page.File.Dir .include }}
{{ $page := site.GetPage "page" $path }}
{{ with $page }}
{{ .Content }}
{{ else }}
{{ errorf "[%s] tabs include not found for path %q" site.Language.Lang $path}}
{{ end }}
{{ end }}
{{ end }}
{{- with .content -}}
{{- . -}}
{{- else -}}
{{- if eq $.Page.BundleType "leaf" -}}
{{- /* find the file somewhere inside the bundle. Note the use of double asterisk */ -}}
{{- with $.Page.Resources.GetMatch (printf "**%s*" .include) -}}
{{- if ne .ResourceType "page" -}}
{{- /* Assume it is a file that needs code highlighting. */ -}}
{{- $codelang := $e.codelang | default ( path.Ext .Name | strings.TrimPrefix ".") -}}
{{- highlight .Content $codelang "" -}}
{{- else -}}
{{- .Content -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $path := path.Join $.Page.File.Dir .include -}}
{{- $page := site.GetPage "page" $path -}}
{{- with $page -}}
{{- .Content -}}
{{- else -}}
{{- errorf "[%s] tabs include not found for path %q" site.Language.Lang $path -}}
{{- end -}}
{{- end -}}
{{- end -}}
</div>
{{ end }}
{{- end -}}
</div>
{{ $elem := $tab_set_id | safeJS }}
<script>$(function(){$("#{{ $elem }}").tabs();});</script>
{{- $elem := $tab_set_id | safeJS -}}
<script>$(function(){$("#{{ $elem }}").tabs();});</script>