themes/geekboot/layouts/partials/version-dropdown-menu.html
{{/* Which versioned track is this page on? "core" (top-level v* sections) or "cli" (subsections of /cli). The track determines which versions appear in the dropdown, which "latest" badges them, and where the fallback section pages live. */}} {{ $track := .Page.Params.track | default "core" }} {{ $latest := .Site.Params.latest }} {{ $sectionPrefix := "v" }} {{ $masterSection := "master" }} {{ $sorted_list := partial "utils/sorted-versions" . }} {{ if eq $track "cli" }} {{ $latest = .Site.Params.cliLatest }} {{ $sectionPrefix = "/cli/v" }} {{ $masterSection = "/cli/master" }} {{ $sorted_list = partial "utils/sorted-versions" (dict "page" . "sections" (.Site.GetPage "/cli").Sections) }} {{ end }} {{ $cur_ver := .Page.Params.version | default $latest }}
{{ if ne .Page.Params.version "master" }}v{{ end }}{{ $cur_ver }} {{ if eq $cur_ver $latest }} Latest {{ end }} {{/* Iterate over the ordered list of available versions. */}} {{ range $sorted_list }} {{ $matchingTitle := $.Title }} {{ if $.Params.matchTitle }} {{ $matchingTitle = $.Params.matchTitle }} {{ end }} {{/* For a version, see if there is a page with an identical title to the page we're on, restricted to the current track so a CLI page can't match a same-titled core page. If none, fall back to the track's section index at /content/. */}} {{ $candidates := where (where $.Site.Pages "Title" $matchingTitle) ".Page.Params.version" . }} {{/* Keep only candidates on the current track: CLI pages live under /cli/, core pages do not. */}} {{ $tracked := slice }} {{ range $candidates }} {{ $isCli := hasPrefix .RelPermalink "/cli/" }} {{ if eq (cond $isCli "cli" "core") $track }} {{ $tracked = $tracked | append . }} {{ end }} {{ end }} {{ $versionPage := index $tracked 0 | default ($.Site.GetPage (printf "%s%s" $sectionPrefix .)) }} {{/* If the version is master get the master page since "vmaster" doesn't exist */}} {{ if not $versionPage }} {{ $versionPage = $.Site.GetPage $masterSection }} {{ end }} {{ with $versionPage }} {{ $isLatest := false }} {{ if or (eq .Page.Params.version "") (eq .Page.Params.version $cur_ver) }} {{ $isLatest = true }} {{ end }} {{ if eq .Page.Params.version "master" }} master {{ else }} {{ if eq .Page.Params.version "" }} {{ (printf "v%s" $latest) }} {{ else }} {{ (printf "v%s" .Page.Params.version) }} {{ end }} {{ end }} {{ if or (eq .Page.Params.version $latest) (eq .Page.Params.version "") }} Latest {{ end }} {{ end }} {{ end }}