{{ $scratch := newScratch }} {{ $productPathData := findRE "[^/]+.*?" .RelPermalink }} {{ $product := index $productPathData 0 | default "influxdb" }} {{ $minorVersions := (index .Site.Data.products $product).versions }} {{ $currentVersion := index $productPathData 1 }} {{ $latestVersion := (index .Site.Data.products $product).latest }} {{ $majorVersion := index (findRE `v[0-9]` $currentVersion) 0 }} {{ $scratch.Set "latestMinorVersion" "" }} {{ if eq $majorVersion "v1"}} {{ $scratch.Set "latestMinorVersion" (index (last 1 (findRE `v1\.[0-9]{1,2}` (delimit $minorVersions " "))) 0) }} {{ else if eq $majorVersion "v2" }} {{ $scratch.Set "latestMinorVersion" (index (last 1 (findRE `v2\.[0-9]{1,2}` (delimit $minorVersions " "))) 0) }} {{ end }} {{ $latestMinorVersion := $scratch.Get "latestMinorVersion" }} {{ $baseURL := replaceRE `\/$` "" .Site.BaseURL }} {{ $scratch.Set "canonicalURL" (print $baseURL .RelPermalink) }} {{ if .Page.Params.canonical }} {{ if in .Page.Params.canonical "{{< latest" }} {{ $product := replaceRE `[ \"]` "" (index (findRE ` \"\w*\"` .Page.Params.canonical) 0) }} {{ $majorVersion := replaceRE `[ \"]` "" (index (findRE ` \"\w*\"` .Page.Params.canonical) 1) }} {{ $minorVersions := (index $.Site.Data.products $product).versions }} {{ $scratch.Set "latestVersion" (index $.Site.Data.products $product).latest }} {{ if gt (len $majorVersion) 0 }} {{ if eq $majorVersion "v1" }} {{ $scratch.Set "latestVersion" (index (last 1 (findRE `v1\.[0-9]{1,2}` (delimit $minorVersions " "))) 0) }} {{ else if eq $majorVersion "v2" }} {{ $scratch.Set "latestVersion" (index (last 1 (findRE `v2\.[0-9]{1,2}` (delimit $minorVersions " "))) 0) }} {{ end }} {{ end }} {{ $productLatestVersion := $scratch.Get "latestVersion" }} {{ $replaceLatest := replaceRE `\{\{\< latest \".*\" \>\}\}` (print $product "/" $productLatestVersion) .Page.Params.canonical }} {{ $scratch.Set "canonicalURL" (print $baseURL $replaceLatest) }} {{ else }} {{ $scratch.Set "canonicalURL" (print $baseURL .Page.Params.canonical) }} {{ end }} {{ else if and (eq $product "influxdb") (eq $currentVersion $latestVersion) }} {{ $correspondingPage := replaceRE `v2\.[0-9]{1,2}` "cloud" (print .Page.File) }} {{ if fileExists $correspondingPage }} {{ if (.Site.GetPage $correspondingPage).HasShortcode "duplicate-oss" }} {{ $scratch.Set "canonicalURL" (print $baseURL (.Site.GetPage $correspondingPage).RelPermalink) }} {{ end }} {{ end }} {{ else if and (ge (len ($productPathData)) 2) (not (isset .Page.Params "canonical")) (ne $currentVersion "cloud") }} {{ range ( index $.Site.Data.products $product ).versions }} {{ $currentURL := $.Page.RelPermalink }} {{ if gt (len ($.GetPage ((replaceRE $currentVersion . $currentURL) | replaceRE `\/$` "")).Title) 0 }} {{ $scratch.Set "canonicalURL" (print $baseURL (replaceRE `v[0-9]\.[0-9]{1,2}` . $currentURL)) }} {{ end }} {{ end }} {{ end }} {{ $canonicalURL := $scratch.Get "canonicalURL" }}