Skip to content

Commit

Permalink
Tabbed pane, fix: avoid duplicate html id if content is pulled in via…
Browse files Browse the repository at this point in the history
… readfile shortcode (#1289)
  • Loading branch information
deining authored and geriom committed Oct 21, 2022
1 parent a2f7ecd commit dd2e2b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 7 additions & 2 deletions layouts/shortcodes/readfile.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{/* Store ordinal, to be retrieved by parent element */}}
{{ if ge hugo.Version "0.93.0" }}
{{ .Page.Store.Add "Ordinal" 1 }}
{{ end }}

{{/* Handle the "file" named parameter or a single unnamed parameter as the file
path */}}
{{ if .IsNamedParams }}
Expand All @@ -24,10 +29,10 @@

{{ if fileExists ($.Scratch.Get "filepath") }}
{{ if eq (.Get "code") "true" }}
{{- highlight ($.Scratch.Get "filepath" | readFile | htmlUnescape |
{{- highlight ($.Scratch.Get "filepath" | readFile | htmlUnescape |
safeHTML ) (.Get "lang") "" -}}
{{ else }}
{{- $.Scratch.Get "filepath" | readFile | .Page.RenderString | htmlUnescape | safeHTML -}}
{{- $.Scratch.Get "filepath" | os.ReadFile | .Page.RenderString | htmlUnescape | safeHTML -}}
{{ end }}
{{ else }}

Expand Down
19 changes: 13 additions & 6 deletions layouts/shortcodes/tabpane.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
{{ $duplicate := false -}}
{{ $duplicateLang := "" -}}

<ul class="nav nav-tabs{{ if $rightPane }} justify-content-end{{ end }}" id="tabs-{{- $.Ordinal -}}" role="tablist">
{{ $Ordinal := $.Ordinal -}}
{{ if ge hugo.Version "0.93.0" -}}
{{ if .Page.Store.Get "Ordinal" -}}
{{ $Ordinal = .Page.Store.Get "Ordinal" -}}
{{end -}}
{{ end -}}

<ul class="nav nav-tabs{{ if $rightPane }} justify-content-end{{ end }}" id="tabs-{{- $Ordinal -}}" role="tablist">
{{ range $index, $element := $.Scratch.Get "tabs" -}}

{{ $disabled := false -}}
Expand Down Expand Up @@ -74,8 +81,8 @@
{{ $lang := replaceRE "[\\s+]" "-" $lang -}}
<li class="nav-item{{ if $rightpush }} ml-auto{{ end -}}">
{{/* Generate the IDs for the <a> and the <div> elements */ -}}
{{ $tabid := printf "tabs-%02v-%v-tab" $.Ordinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $.Ordinal $index | anchorize -}}
{{ $tabid := printf "tabs-%02v-%v-tab" $Ordinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $Ordinal $index | anchorize -}}

<a class="nav-link{{ if and ( not $activeSet ) ( not $disabled ) }} active{{ end }}{{ if $disabled }} disabled{{ end }}{{ if ne $lang "" }}{{ if and $persistLang (not $duplicate) }} persistLang-{{- $lang -}}{{ end }}{{ end }}"
id="{{ $tabid }}" data-toggle="tab" href="#{{ $entryid }}" role="tab"
Expand All @@ -100,7 +107,7 @@
{{ $activeSet = false -}}

{{/* Inner content */ -}}
<div class="tab-content" id="tabs-{{ $.Ordinal }}-content">
<div class="tab-content" id="tabs-{{ $Ordinal }}-content">
{{- range $index, $element := $.Scratch.Get "tabs" -}}

{{ $lang := $langPane -}}
Expand All @@ -126,8 +133,8 @@
{{ $text = . }}
{{ end -}}

{{ $tabid := printf "tabs-%02v-%v-tab" $.Ordinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $.Ordinal $index | anchorize }}
{{ $tabid := printf "tabs-%02v-%v-tab" $Ordinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $Ordinal $index | anchorize }}
<div class="{{ if $text }}tab-body {{end}}tab-pane fade{{ if and ( not $activeSet ) ( not $disabled ) }} show active{{ end }}"
id="{{ $entryid }}" role="tabpanel" aria-labelled-by="{{ $tabid }}">
{{ if $text -}}
Expand Down

0 comments on commit dd2e2b9

Please sign in to comment.