-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathnavbar-version-selector.html
More file actions
29 lines (28 loc) · 1.03 KB
/
navbar-version-selector.html
File metadata and controls
29 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{{/* set sane defaults */}}
{{ $.Scratch.Set "docLabel" "Version " }}
{{ $.Scratch.Set "activeVersion" .Site.Params.version }}
{{ $curPage := .Page.Section }}
{{/* find version matching the current page */}}
{{ range .Site.Params.versions }}
{{ if eq $curPage .dirpath }}
{{ $.Scratch.Add "docLabel" (printf "(%s)" .version) }}
{{ $.Scratch.Set "activeVersion" .version }}
{{ end }}
{{ end }}
{{ if .Site.Params.versions }}
<button class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ printf "%s" ($.Scratch.Get "docLabel") }}
</button>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
{{ range .Site.Params.versions }}
{{ if and .url (ne .url "") }}
<a
class="dropdown-item{{ if eq ( $.Scratch.Get "activeVersion" ) ( printf "%s" .version ) }} active{{ end }}"
href="{{ cond (gt (len (findRE "^http(s)?://" .url)) 0) .url (relURL .url) }}"
>
{{ .version }}
</a>
{{ end }}
{{ end }}
</div>
{{ end }}