46 lines
1.2 KiB
HTML
46 lines
1.2 KiB
HTML
{{ $scratch := newScratch }}
|
|
{{ $baseURL := replaceRE `\/$` "" .Site.BaseURL }}
|
|
|
|
<!-- Set the current page as the default canonical URL -->
|
|
{{ $scratch.Set "canonicalURL" (print $baseURL .RelPermalink) }}
|
|
|
|
<!-- Set canonical URL using 'canonical' frontmatter -->
|
|
{{ if .Page.Params.canonical }}
|
|
{{ $scratch.Set "canonicalURL" (print $baseURL .Page.Params.canonical) }}
|
|
|
|
<!--
|
|
Set canonical URL from pages with the same shared source. Select one page from
|
|
those that share the same source using the following product priority order:
|
|
|
|
1. enterprise
|
|
2. core
|
|
3. cloud-dedicated
|
|
4. clustered
|
|
5. cloud-serverless
|
|
6. v2
|
|
7. cloud
|
|
-->
|
|
{{ else if .Page.Params.source }}
|
|
{{ $productPriority := slice
|
|
"/enterprise/"
|
|
"/core/"
|
|
"/cloud-dedicated/"
|
|
"/clustered/"
|
|
"/cloud-serverless/"
|
|
"/v2/"
|
|
"/cloud/"
|
|
}}
|
|
{{ range where (sort .Site.Pages "Section" "desc") "Params.source" "eq" .Page.Params.source }}
|
|
{{ $pagePath := .RelPermalink }}
|
|
{{ range $productPriority }}
|
|
{{ if in $pagePath . }}
|
|
{{ $scratch.Set "canonicalURL" (print $baseURL $pagePath) }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ $canonicalURL := $scratch.Get "canonicalURL" }}
|
|
|
|
<link rel="canonical" href="{{ $canonicalURL }}" />
|