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

Martin Hellspong
05.27.2023 473ff712bdbecc0f9727ffe1bab49135191f19d1
refs
author Martin Hellspong <martin.hellspong@factor10.com>
Thursday, January 5, 2023 13:27 +0100
committer GitHub <noreply@github.com>
Thursday, January 5, 2023 13:27 +0100
commit473ff712bdbecc0f9727ffe1bab49135191f19d1
tree 1c555305ca91e8f0d3f45fc0fc7a3181fdffd9f0 tree | zip | gz
parent aed63c6f967c43c1337fb2df850f37f715b7ed7f view | diff
Add custom title / translation of categories (#755)

### Prerequisites

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

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

### Description

This PR is similar to #754, but updates the categories to utilize Hugos
taxonomy system, instead of the tags .

This PR edits the posts/single layout to use `.GetTerms "categories"` to
fetch a richer model of the categories, and the taxonomy/categories
partial to use this model, instead of just urlizing the category name,
so categories with a custom title, renders correctly on a post.

This also enables translation of the categories shown on a post, while
enabling switching languages on the category page without losing
context.

To show this in action, I've added a translation of the "themes" and
"syntax" categories in the exampleSite into PT-BR, as "temas" and
"sintaxe", respectively, and switched the pt-br page to use the english
category ids so they are seen as the same category regardless of
translation.


![image](https://user-images.githubusercontent.com/2725205/210677278-908bd3fc-5edb-4c40-ab53-270d148dd061.png)

Also, this enables customizing/translating the category url, by
specifying a slug and/or url in the category frontmatter.


![image](https://user-images.githubusercontent.com/2725205/210677524-9eece29d-e110-406b-9db0-5d8b4406b112.png)

If you switch languages here on the category page, you'll see the
translated category and corresponding posts, instead of dropping out to
the front page like before.

### Issues Resolved

If you wanted to use Hugo taxonomy system for the page categories, only
the category id showed up on the post itself. This PR fixes that.

### 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

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

Co-authored-by: Luiz F. A. de PrĂ¡ <luizdepra@users.noreply.github.com>
2 files added
3 files modified
20 ■■■■ changed files
exampleSite/content/categories/syntax/_index.pt-br.md 6 ●●●●● diff | view | raw | blame | history
exampleSite/content/categories/themes/_index.pt-br.md 6 ●●●●● diff | view | raw | blame | history
exampleSite/content/posts/markdown-syntax.pt-br.md 4 ●●●● diff | view | raw | blame | history
layouts/partials/taxonomy/categories.html 2 ●●● diff | view | raw | blame | history
layouts/posts/single.html 2 ●●● diff | view | raw | blame | history