From c5ab16b677a66653a584fcb0b8f7929d122d480e Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 10 Aug 2020 09:42:41 -0600 Subject: [PATCH] updated canonical tag partial --- layouts/partials/header/canonical.html | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/layouts/partials/header/canonical.html b/layouts/partials/header/canonical.html index 5403a0af5..221a282e1 100644 --- a/layouts/partials/header/canonical.html +++ b/layouts/partials/header/canonical.html @@ -1,4 +1,26 @@ -{{ $stableVersion := $.Site.Data.versions.stable_version }} -{{ $canonicalURL := print (replaceRE `\/$` "" .Site.BaseURL) (replaceRE "[^/]+.*?[0]" $stableVersion .RelPermalink) }} +{{ $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 gt (len (findRE "[^/]+.*?" .RelPermalink)) 2 }} + {{ $scratch.Set "canonicalURL" (print $baseURL (replaceRE `v[0-9]\.[0-9]{1,2}` $latestMinorVersion .RelPermalink))}} +{{ end }} + +{{ $canonicalURL := $scratch.Get "canonicalURL" }}