feat: add canonical url support (#650)

When you want to publish content that is already published on a different site. You need to reference a canonical url of the original content.
By defining the `canonicalUrl` in the front matter definition the canonical url is set in the headers.
This commit is contained in:
Joris Conijn 2023-11-21 20:41:58 +01:00 committed by GitHub
parent 4ea29d886c
commit 221a0d8817
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View file

@ -334,6 +334,14 @@ Dates of blog posts and single pages are rendered with the default date format c
With hugo 0.87.0 and above, you can also use predefined layout, like `:date_full`, and it will output localized dates or times. With hugo 0.87.0 and above, you can also use predefined layout, like `:date_full`, and it will output localized dates or times.
See hugo's documentation of the [`time.Format` function](https://gohugo.io/functions/dateformat/) for more details. See hugo's documentation of the [`time.Format` function](https://gohugo.io/functions/dateformat/) for more details.
### Using a canonical url
When you want to publish content that is already published on a different site. You need to reference a canonical url of the original content.
By defining the `canonicalUrl` in the front matter definition the canonical url is set in the headers.
```
canonicalUrl: https://mydomain.com/path-to-the-oringinal-content/
```
### Nearly finished ### Nearly finished

View file

@ -31,6 +31,12 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ if .Params.canonicalUrl }}
<link rel="canonical" href="{{ .Params.canonicalUrl }}">
{{ else }}
<link rel="canonical" href="{{ .Permalink }}">
{{ end }}
{{/* NOTE: These Hugo Internal Templates can be found starting at https://github.com/gohugoio/hugo/tree/master/tpl/tplimpl/embedded/templates */}} {{/* NOTE: These Hugo Internal Templates can be found starting at https://github.com/gohugoio/hugo/tree/master/tpl/tplimpl/embedded/templates */}}
{{- template "_internal/opengraph.html" . -}} {{- template "_internal/opengraph.html" . -}}
{{- template "_internal/schema.html" . -}} {{- template "_internal/schema.html" . -}}