docs-v2/layouts/partials/article/stable-version.html

81 lines
4.1 KiB
HTML

{{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
{{ $product := index $productPathData 0 }}
{{ $version := index $productPathData 1 | default "0"}}
{{ $productKey := cond (eq $product "influxdb3") (print "influxdb3_" (replaceRE "-" "_" $version)) $product }}
<!-- Initialize version variables -->
{{ $successorInfo := dict "exists" false }}
{{ $productName := $product | humanize }}
{{ $stableVersion := "" }}
{{ $stableVersionURL := "" }}
{{ $stableDefaultURL := "" }}
<!-- Get current product name -->
{{ if isset .Site.Data.products $productKey }}
{{ $productName = cond (isset (index .Site.Data.products $productKey) "altname") (index .Site.Data.products $productKey).altname (index .Site.Data.products $productKey).name }}
{{ end }}
<!-- Check for successor and get version information -->
{{ if and (isset .Site.Data.products $productKey) (isset (index .Site.Data.products $productKey) "succeeded_by") }}
{{ $successorKey := (index .Site.Data.products $productKey).succeeded_by }}
{{ if and $successorKey (isset .Site.Data.products $successorKey) }}
<!-- Successor exists and is valid -->
{{ $successorInfo = dict
"exists" true
"key" $successorKey
"name" (cond (isset (index .Site.Data.products $successorKey) "altname")
(index .Site.Data.products $successorKey).altname
(index .Site.Data.products $successorKey).name)
"version" (replaceRE `\.[0-9x]+$` "" (index .Site.Data.products $successorKey).latest)
"namespace" (index .Site.Data.products $successorKey).namespace
}}
<!-- Set stable version to successor version -->
{{ $stableVersion = $successorInfo.version }}
{{ $stableVersionURL = print "/" $successorInfo.namespace "/" $stableVersion "/" }}
{{ $stableDefaultURL = $stableVersionURL }}
{{ end }}
{{ else if isset .Site.Data.products $product }}
<!-- No successor, use current product's latest version -->
{{ $stableVersion = (replaceRE `\.[0-9x]+$` "" (index .Site.Data.products $product).latest) }}
{{ $stableVersionURL = replaceRE `v[1-3]` $stableVersion .RelPermalink }}
{{ $stableDefaultURL = print "/" $product "/" $stableVersion "/" }}
{{ end }}
{{ $stableEquivalentURL := index .Page.Params.alt_links $stableVersion | default "does-not-exist" }}
{{ $stableEquivalentPage := .GetPage (replaceRE `\/$` "" $stableEquivalentURL) }}
{{ $stablePageExists := gt (len $stableEquivalentPage.Title) 0 }}
{{ $productWhiteList := slice "telegraf" "influxdb" "chronograf" "kapacitor" "flux" }}
{{ $isMultiVersion := in (print "/" $version) "/v" }}
{{ if and (in $productWhiteList $product) $isMultiVersion }}
{{ if $successorInfo.exists }}
<!-- Show callout for product with successor -->
<div class="warn block old-version">
<p>
This page documents an earlier version of {{ $productName }}.
<a href="{{ $stableDefaultURL }}">{{ $successorInfo.name }}</a> is the latest stable version.
</p>
</div>
{{ else if $stableVersion }}
<!-- Show callout for product with newer version (no successor) -->
{{ if lt (int (replaceRE `[a-z]` "" $version)) (int (replaceRE `[a-z]` "" $stableVersion)) }}
<div class="warn block old-version">
<p>
This page documents an earlier version of {{ $productName }}.
<a href="/{{ $product }}/{{ $stableVersion }}/">{{ $productName }} {{ $stableVersion }}</a> is the latest stable version.
<!-- Handle page navigation options -->
{{ if gt (len (.GetPage ((replaceRE `v[1-3]` $stableVersion .RelPermalink) | replaceRE `\/$` "")).Title) 0 }}
<a href="{{ $stableVersionURL }}">View this page in the {{ $stableVersion }} documentation</a>.
{{ else if $stablePageExists }}
<span style="margin-right:.25rem">See the equivalent <strong>{{ $productName }} {{ $stableVersion }}</strong> documentation:</span> <a href="{{ $stableEquivalentPage.RelPermalink }}">{{ $stableEquivalentPage.Title | .RenderString }}</a>.
{{ else }}
See the <a href="{{ $stableDefaultURL }}">{{ $productName }} {{ $stableVersion }} documentation</a>.
{{ end }}
</p>
</div>
{{ end }}
{{ end }}
{{ end }}