{{ $currentVersion := (index (findRE "[^/]+.*?" .RelPermalink) 0) .RelPermalink }}
{{ $latestVersion := $.Site.Data.versions.latest_version }}
{{ $latestPath := replaceRE "[^/]+.*?[0]" $latestVersion .RelPermalink }}
{{ $canonicalURL := print (replaceRE `\/$` "" .Site.BaseURL) (replaceRE "[^/]+.*?[0]" $latestVersion .RelPermalink) }}

{{ if not (eq $currentVersion $latestVersion) }}
  <link rel="canonical" href="{{ $canonicalURL }}" />
{{ end }}
