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

48 lines
2.9 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 }}
{{ $productName := cond (isset (index .Site.Data.products $productKey) "altname") (index .Site.Data.products $productKey).altname (index .Site.Data.products $productKey).name }}
{{ $stableVersion := (replaceRE `\.[0-9x]+$` "" (index .Site.Data.products $product).latest) }}
{{ $stableVersionURL := replaceRE `v[1-3]` $stableVersion .RelPermalink }}
{{ $stableDefaultURL := print "/" $product "/" $stableVersion "/" }}
{{ $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 }}
<!-- Check if the current version is less than the stable version -->
{{ 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.
<!-- Check if page exists in latest major version docs -->
{{ if gt (len (.GetPage ((replaceRE `v[1-3]` $stableVersion .RelPermalink) | replaceRE `\/$` "")).Title) 0 }}
<a href="{{ $stableVersionURL }}">View this page in the {{ $stableVersion }} documentation</a>.
<!-- Check if the stable equivalent page exists -->
{{ else if $stablePageExists }}
<span style="margin-right:.25rem">See the equivalent <strong>InfluxDB {{ $stableVersion }}</strong> documentation:</span> <a href="{{ $stableEquivalentPage.RelPermalink }}">{{ $stableEquivalentPage.Title | .RenderString }}</a>.
{{ else }}
See the <a href="{{ $stableDefaultURL }}">InfluxDB {{ $stableVersion }} documentation</a>.
{{ end }}
</p>
</div>
{{ end }}
{{ end }}
{{ if and .Page.Params.v2 (eq (findRE `v[1-3]` $version) (findRE `v[1-3]` $stableVersion)) }}
<div class="note block old-version">
<p>
{{ if $stablePageExists }}
<span style="margin-right:.25rem">See the equivalent <strong>InfluxDB {{ $stableVersion }}</strong> documentation:</span> <a href="{{ $stableEquivalentPage.RelPermalink }}">{{ $stableEquivalentPage.Title | .RenderString }}</a>.
{{ else }}
See the <a href="{{ $stableEquivalentURL }}">equivalent InfluxDB {{ $stableVersion }} documentation</a>.
{{ end }}
</p>
</div>
{{ end }}