docs: add canonical link ref

Adds a canonical link tag to doc pages
to help SEO find the current version of
documentation.

Signed-off-by: Tim Jones <tim.jones@siderolabs.com>
This commit is contained in:
Tim Jones 2022-04-20 10:21:20 +02:00
parent 0fe4a7832b
commit e8cbedb05b
No known key found for this signature in database
GPG Key ID: A2A702DD5B689F45
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,5 @@
[build]
command = "cd website && hugo --gc --minify"
command = "cd website && hugo --gc --minify --baseURL $DEPLOY_PRIME_URL"
publish = "website/public"
[build.environment]

View File

@ -4,3 +4,15 @@
{{ if (findRE "<pre" .Content 1) }}
<link rel="stylesheet" href="/css/clipboard.css">
{{ end }}
<!--- https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls?hl=en#rel-canonical-link-method -->
{{ if .Section }}
{{ $latest_version := .Site.Params.url_latest_version }}
{{ $current_version := .Section | printf "/%s" }}
{{ if ne $latest_version $current_version }}
{{ $latest_doc := partial "doc_latest_version.html" . }}
{{ if ne $latest_doc $latest_version }}
<link rel="canonical" href="{{ $latest_doc | safeURL | absURL }}" />
{{ end }}
{{ end }}
{{ end }}