mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Joris Conijn
21.41.2023 221a0d881758f6b6b7fba99eecb894cd5fa911ec
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.
2 files modified
14 ■■■■■ changed files
README.md 8 ●●●●● patch | view | raw | blame | history
layouts/_default/baseof.html 6 ●●●●● patch | view | raw | blame | history
README.md
@@ -334,6 +334,14 @@
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.
### 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
layouts/_default/baseof.html
@@ -31,6 +31,12 @@
      {{ 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 */}}
    {{- template "_internal/opengraph.html" . -}}
    {{- template "_internal/schema.html" . -}}