Skip to content

Commit 083b23b

Browse files
feat: Add Version selector dropdown (#16746)
* Add Version selector dropdown * Fix Responsiveness * More maintainable code * Address Craig`s Suggestion Co-authored-by: Craig Box <[email protected]> * More cleaner UI Co-authored-by: Craig Box <[email protected]> * Stop generating drop-down in archive docs Co-authored-by: Craig Box <[email protected]> * Fix : Mobile View Co-authored-by: Craig Box <[email protected]> * More Styling Co-authored-by: Craig Box <[email protected]> * Fix: Mobile Co-authored-by: Craig Box <[email protected]> * Update Rendering Logic Co-authored-by: Craig Box <[email protected]> * Add boolean logic from data/args.yml Co-authored-by: Craig Box <[email protected]> * Remove accidental package.json file * Update Makefile * Update version-selector.html * Update version-selector.html * Update layouts/partials/version-selector.html Co-authored-by: Craig Box <[email protected]> * Update layouts/partials/version-selector.html Co-authored-by: Craig Box <[email protected]> --------- Co-authored-by: Craig Box <[email protected]>
1 parent 6c22152 commit 083b23b

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

layouts/partials/header.html

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,26 @@
2323
{{ $currentPage := .}}
2424
{{ range .Site.Menus.main }}
2525
{{ $active := or (eq $currentPage.Title .Name) (or ($currentPage.HasMenuCurrent "main" .) ($currentPage.IsMenuCurrent "main" .)) }}
26-
{{ if .HasChildren }}
26+
{{ if and (eq .Identifier "docs") (eq $.Section "docs") (not $.Site.Data.args.archive) }}
27+
<li class="main-navigation-links-item">
28+
<a href="{{ .URL | relLangURL }}" class="main-navigation-links-link has-dropdown {{ if $active }}active{{ end }}">
29+
<span>{{ .Name }}</span>
30+
{{ partial "icon.html" "dropdown-arrow" }}
31+
</a>
32+
33+
<ul class="main-navigation-links-dropdown">
34+
{{ range .Children }}
35+
<li class="main-navigation-links-dropdown-item">
36+
<a href="{{ .URL | relLangURL }}" class="main-navigation-links-link">{{ .Name }}</a>
37+
</li>
38+
{{ end }}
39+
40+
41+
{{ partial "version-selector.html" $ }}
42+
43+
</ul>
44+
</li>
45+
{{else if .HasChildren }}
2746
<li class="main-navigation-links-item">
2847
<a {{ if ne .URL "" }}href="{{ .URL | relLangURL }}"{{end}} class="main-navigation-links-link has-dropdown {{ if $active }}active{{ end }}">
2948
<span>{{ .Name }}</span>
@@ -48,11 +67,12 @@
4867
{{ end }}
4968
</ul>
5069

70+
71+
5172
<div class="main-navigation-footer">
5273
<button id="search-show" class="search-show" title='{{ i18n "search" }}' aria-label='{{ i18n "search_label" }}'>{{ partial "icon.html" "magnifier" }}</button>
5374
<a href='{{ "/docs/overview/quickstart" | relLangURL }}' class="btn btn--primary" id="try-istio">{{ i18n "try_istio" }}</a>
5475
</div>
55-
5676
</div>
5777

5878
<form id="search-form" class="search" name="cse" role="search">
@@ -69,5 +89,7 @@
6989
<input id="search-textbox" class="search-textbox form-control" name="q" type="search" aria-label='{{ i18n "search" }}' placeholder='{{ i18n "search_label" }}' />
7090
<button id="search-close" title='{{ i18n "search_cancel" }}' type="reset" aria-label='{{ i18n "search_cancel" }}'>{{ partial "icon.html" "menu-close" }}</button>
7191
</form>
92+
93+
7294
</nav>
7395
</header>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{{ $versions := site.Data.versions }}
2+
{{ $mainVerStr := $versions.main }}
3+
{{ $preliminaryVerStr := $versions.preliminary }}
4+
{{ $mainVerParts := split $mainVerStr "." }}
5+
{{ $major := index $mainVerParts 0 | int }}
6+
{{ $minor := index $mainVerParts 1 | int }}
7+
{{ $versionCount := 5 }}
8+
9+
<!-- Preliminary version -->
10+
{{ $preUrl := printf "https://preliminary.istio.io/v%s/docs" $preliminaryVerStr }}
11+
<li class="main-navigation-links-dropdown-item">
12+
<a href="{{ $preUrl }}"
13+
class="main-navigation-links-link">
14+
Preliminary
15+
</a>
16+
</li>
17+
18+
<!-- Main version -->
19+
{{ $mainUrl := printf "https://istio.io/v%s/docs" $mainVerStr }}
20+
<li class="main-navigation-links-dropdown-item">
21+
<a href="{{ $mainUrl }}"
22+
class="main-navigation-links-link">
23+
<strong>v{{ $mainVerStr }} (Current)</strong>
24+
</a>
25+
</li>
26+
27+
<!-- Previous versions -->
28+
{{ range $i := seq 1 (sub $versionCount 1) }}
29+
{{ $currentMinor := sub $minor $i }}
30+
{{ if ge $currentMinor 0 }}
31+
{{ $ver := printf "v%d.%d" $major $currentMinor }}
32+
{{ $url := printf "https://istio.io/%s/docs" $ver }}
33+
<li class="main-navigation-links-dropdown-item">
34+
<a href="{{ $url }}"
35+
class="main-navigation-links-link">
36+
{{ $ver }}
37+
</a>
38+
</li>
39+
{{ end }}
40+
{{ end }}

0 commit comments

Comments
 (0)