static/frontend/unit: add canonical href link

To prevent search engines from indexing duplicate unit pages
and different minor or patch versions, we provide a canonical
URL for all unit main pages.

Change-Id: Ida6f40f11b3c860dffad9a6fc843d58ac56d5693
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/341864
Trust: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/static/frontend/frontend.tmpl b/static/frontend/frontend.tmpl
index d93e6f9..4fcf25e 100644
--- a/static/frontend/frontend.tmpl
+++ b/static/frontend/frontend.tmpl
@@ -27,6 +27,7 @@
     {{end}}
     <meta class="js-gtmID" data-gtmid="{{.GoogleTagManagerID}}">
     <link rel="shortcut icon" href="/static/shared/icon/favicon.ico">
+    {{block "canonical" .}}{{end}}
     <!-- Only load the css reset for non-legacy pages -->
     {{if not .UseSiteWrapper}}
       <link href="/static/shared/reset.css?version={{.AppVersionLabel}}" rel="stylesheet">
diff --git a/static/frontend/unit/main/main.tmpl b/static/frontend/unit/main/main.tmpl
index f0e697c..00924b7 100644
--- a/static/frontend/unit/main/main.tmpl
+++ b/static/frontend/unit/main/main.tmpl
@@ -4,6 +4,10 @@
   license that can be found in the LICENSE file.
 -->
 
+{{define "canonical"}}
+  <link rel="canonical" href="https://pkg.go.dev/{{.Unit.Path}}">
+{{end}}
+
 {{define "main-styles"}}
   <link href="/static/frontend/unit/main/main.css?version={{.AppVersionLabel}}" rel="stylesheet">
 {{end}}