From 16543fdb8598dc97091cc9315b2461d052a31e2f Mon Sep 17 00:00:00 2001 From: Archit Sharma <74408634+iArchitSharma@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:49:29 +0000 Subject: [PATCH] Added Support for Canonical page link in
Signed-off-by: Archit Sharma <74408634+iArchitSharma@users.noreply.github.com> --- layouts/partials/hooks/head-end.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/layouts/partials/hooks/head-end.html b/layouts/partials/hooks/head-end.html index e69de29bb2..e77c7d3475 100644 --- a/layouts/partials/hooks/head-end.html +++ b/layouts/partials/hooks/head-end.html @@ -0,0 +1,26 @@ +{{ with .Params.canonical_url -}} + + + +{{- else -}} + + {{ $canonicalURL := .Permalink -}} + + {{ $defaultLang := "en" -}} + {{ if and (ne .Language.Lang $defaultLang) .File -}} + + {{ $pagePath := strings.TrimPrefix (add hugo.WorkingDir "/content/") .File.Filename -}} + {{ if hasPrefix $pagePath $defaultLang -}} + + + + {{ $translationPages := where .Translations "Lang" $defaultLang -}} + {{ $translation := index $translationPages 0 -}} + {{ with $translation -}} + {{ $canonicalURL = .Permalink -}} + {{ end -}} + {{ end -}} + {{ end -}} + + +{{- end -}} \ No newline at end of file