mirror of https://github.com/luizdepra/hugo-coder.git

Kemal Akkoyun
13.14.2023 44fdec2a2291128162f1bfcc6d4ed47ba97f633f
Utilize canonical URLs if specified in front matter (#827)

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

### Prerequisites

Put an `x` into the box(es) that apply:

- [ ] This pull request fixes a bug.
- [x] This pull request adds a feature.
- [ ] This pull request introduces breaking change.

### Description

To prevent hurting the SEO when a blog post re-posted, it's recommended
to use canonical URL tags.
This PR updates the concerning metatag if `canonicalUrl` specified in
front matter.

See working example:
- https://kakkoyun.me/posts/fantastic-symbols-and-where-to-find-them
-
https://github.com/kakkoyun/me/blob/master/content/posts/fantastic-symbols-and-where-to-find-them.md

### Checklist

Put an `x` into the box(es) that apply:

#### General

- [x] Describe what changes are being made
- [x] Explain why and how the changes were necessary and implemented
respectively
- [ ] Reference issue with `#<ISSUE_NO>` if applicable

#### Resources

- [ ] If you have changed any SCSS code, run `make release` to
regenerate all CSS files

#### Contributors

- [x] Add yourself to `CONTRIBUTORS.md` if you aren't on it already

---------

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
3 files modified
8 ■■■■ changed files
CONTRIBUTORS.md 1 ●●●● patch | view | raw | blame | history
docs/configurations.md 3 ●●●● patch | view | raw | blame | history
layouts/partials/head.html 4 ●●● patch | view | raw | blame | history
CONTRIBUTORS.md
@@ -132,3 +132,4 @@
- [Fei Kong](https://github.com/alpha0422)
- [Ahmet Enes Bayraktar](https://github.com/aeb-dev)
- [Todor Bogosavljević](https://github.com/tbx1b)
- [Kemal Akkoyun](https://github.com/kakkoyun)
docs/configurations.md
@@ -319,7 +319,7 @@
These are the front matter variables used by `hugo-coder` theme.
| Name             | Type   | Required | Description                                        | Default | Example                                                                       |
| ---------------- | ------ | -------- | -------------------------------------------------- | ------- | ----------------------------------------------------------------------------- |
| ---------------- | ------ | -------- | -------------------------------------------------- | ------- | ------------------------------------------------------------------------------- |
| tags             | list   | No       | Add tag(s) to this post.                           |         | `["Hugo", "Go"]`                                                              |
| categories       | list   | No       | Add categorie(s) to this post.                     |         | `["Hugo", "Go"]`                                                              |
| series           | list   | No       | Add series to this post (used by OpenGraph).       |         | `["Theme Demo"]`                                                              |
@@ -329,5 +329,6 @@
| math             | bool   | No       | If true, MathJax is enabled only for this post.    | `false` | `true` or `false`                                                             |
| katex            | bool   | No       | If true, katex is enabled only for this post.      | `false` | `true` or `false`                                                             |
| disableComments  | bool   | No       | If true, comments are disabled.                    | `false` | `true` or `false`                                                             |
| canonicalUrl     | string | No       | Link to override <link rel="canonical"/> in <head> | `false` | `"https://my-company.com/blog/my-blog-post-that-I-repost-without-hurtiong-seo"` |
> "tags", "categories", "series" and "authors" are taxonomies defined in the `config.toml` file.
layouts/partials/head.html
@@ -1,6 +1,8 @@
{{ partial "head/meta-tags.html" . }}
{{ if .Permalink }}
{{ if .Params.canonicalUrl }}
<link rel="canonical" href="{{ .Params.canonicalUrl }}">
{{ else }}
<link rel="canonical" href="{{ .Permalink }}">
{{ end }}