docs-v2/layouts/partials/topnav/version-selector.html

30 lines
1.2 KiB
HTML

{{ $scratch := newScratch }}
{{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
{{ $product := index $productPathData 0 }}
{{ $currentVersion := index $productPathData 1 }}
{{ if or (eq $product nil) (lt (len (findRE `v[0-2]\.[0-9x]{1,2}` $currentVersion)) 1) }}
{{ else }}
<div class="dropdown">
<p class="selected">{{ cond (in $currentVersion "v") $currentVersion (title $currentVersion) }}</p>
<ul class="item-list versions">
{{ if ne $product "flux" }}
<li><a href="https://archive.docs.influxdata.com/{{ $product }}/" class="legacy" target="_blank">older</a></li>
{{ end }}
{{ range (index .Site.Data.products $product).versions }}
{{ $scratch.Set "link" (print "/" $product "/" . "/") }}
{{ $altVersionPage := $.GetPage ((replaceRE $currentVersion . $.Page.RelPermalink) | replaceRE `\/$` "") }}
{{ if gt (len $altVersionPage.Title) 0 }}
{{ $scratch.Set "link" $altVersionPage.RelPermalink }}
{{ else if eq . $currentVersion }}
{{ $scratch.Set "link" "" }}
{{ end }}
{{ $link := $scratch.Get "link" }}
<li>
<a href="{{ $link }}" {{ if eq . $currentVersion }}class="active"{{ end }}>{{ cond (in . "v") . (title .) }}</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}