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

50 lines
2.9 KiB
HTML

{{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
{{ $product := index $productPathData 0 }}
{{ $productName := cond (isset (index .Site.Data.products $product) "altname") (index .Site.Data.products $product).altname (index .Site.Data.products $product).name }}
{{ $currentVersion := index $productPathData 1 }}
{{ $latestV2 := index (.Site.Data.products.influxdb.versions) 0 }}
{{ $stableVersion := (replaceRE `\.[0-9x]+$` "" (index .Site.Data.products $product).latest) }}
{{ $stableVersionURL := replaceRE `v[1-2]` $stableVersion .RelPermalink }}
{{ $v2EquivalentURL := replaceRE `v[1-2]` $latestV2 .Page.Params.v2 }}
{{ $v2EquivalentPage := .GetPage (replaceRE `\/$` "" $v2EquivalentURL) }}
{{ $v2PageExists := gt (len $v2EquivalentPage.Title) 0 }}
{{ $isResources := in .Page.RelPermalink "/resources/" }}
{{ $isPlatform := in .Page.RelPermalink "/platform/" }}
{{ $isCloud := in .Page.RelPermalink "/influxdb/cloud" }}
{{ $isClustered := in .Page.RelPermalink "/influxdb/clustered" }}
{{ if and (ne $currentVersion $stableVersion) (not (or $isCloud $isClustered $isResources $isPlatform)) }}
<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.
{{ if eq (findRE `v[1-2]` $currentVersion) (findRE `v[1-2]` $stableVersion) }}
<!-- Check if page exists in latest major version docs -->
{{ if gt (len (.GetPage ((replaceRE `v[1-2]\.[0-9]{1,2}` (index .Site.Data.products $product).latest .RelPermalink) | replaceRE `\/$` "")).Title) 0 }}
<a href="{{ $stableVersionURL }}">View this page in the {{ $stableVersion }} documentation</a>.
{{ end }}
{{ else if and (ne (findRE `v[1-2]` $currentVersion) (findRE `v[1-2]` $stableVersion)) (.Page.Params.v2) }}
<!-- Check if the v2 equivalent page exists -->
{{ if $v2PageExists }}
<span style="margin-right:.25rem">See the equivalent <strong>InfluxDB {{ $latestV2 }}</strong> documentation:</span> <a href="{{ $v2EquivalentPage.RelPermalink }}">{{ $v2EquivalentPage.Title }}</a>.
{{ else }}
See the <a href="{{ $v2EquivalentURL }}">equivalent InfluxDB {{ $latestV2 }} documentation</a>.
{{ end }}
{{ end }}
</p>
</div>
{{ end }}
{{ if and .Page.Params.v2 (eq (findRE `v[1-2]` $currentVersion) (findRE `v[1-2]` $stableVersion)) }}
<div class="note block old-version">
<p>
{{ if $v2PageExists }}
<span style="margin-right:.25rem">See the equivalent <strong>InfluxDB {{ $latestV2 }}</strong> documentation:</span> <a href="{{ $v2EquivalentPage.RelPermalink }}">{{ $v2EquivalentPage.Title }}</a>.
{{ else }}
See the <a href="{{ $v2EquivalentURL }}">equivalent InfluxDB {{ $latestV2 }} documentation</a>.
{{ end }}
</p>
</div>
{{ end }}