taxonomy: add support for category default taxonomy #541

This commit is contained in:
Sören Weber 2023-05-26 08:35:27 +02:00
parent 9222821974
commit c25bc2a27a
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
9 changed files with 75 additions and 50 deletions

View file

@ -31,7 +31,7 @@ The Relearn theme is a fork of the great [Learn theme](https://github.com/matcor
- In page search - In page search
- [Site search](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-search) - [Site search](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-search)
- [Dedicated search page](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-dedicated-search-page) - [Dedicated search page](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-dedicated-search-page)
- [Tagging support](https://mcshelby.github.io/hugo-theme-relearn/cont/tags) - [Taxonomy support](https://mcshelby.github.io/hugo-theme-relearn/cont/taxonomy)
- Hidden pages - Hidden pages
- Unlimited nested menu dependend on your site structure - Unlimited nested menu dependend on your site structure
- Navigation buttons dependend on your site structure - Navigation buttons dependend on your site structure

View file

@ -34,7 +34,7 @@ The theme is a fork of the great [Learn theme](https://github.com/matcornic/hugo
- In page search - In page search
- [Site search]({{%relref "basics/configuration#activate-search" %}}) - [Site search]({{%relref "basics/configuration#activate-search" %}})
- [Dedicated search page]({{%relref "basics/configuration#activate-dedicated-search-page" %}}) - [Dedicated search page]({{%relref "basics/configuration#activate-dedicated-search-page" %}})
- [Tagging support]({{%relref "cont/tags" %}}) - [Taxonomy support]({{%relref "cont/taxonomy" %}})
- Hidden pages - Hidden pages
- Unlimited nested menu dependend on your site structure - Unlimited nested menu dependend on your site structure
- Navigation buttons dependend on your site structure - Navigation buttons dependend on your site structure

View file

@ -18,6 +18,12 @@ This document shows you what's new in the latest release. For a detailed list of
--- ---
## 5.16.0 (2023-05-25)
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Besides the _tag_ [taxonomy]({{% relref "cont/taxonomy" %}}) the theme now also provides the _category_ taxonomy out of the box and shows them in the content footer of each page.
---
## 5.15.0 (2023-05-25) ## 5.15.0 (2023-05-25)
- {{% badge style="note" title=" " %}}Change{{% /badge %}} The [`tabs` shortcode]({{% relref "shortcodes/tabs" %}}) has changed behavior if you haven't set the `groupid` parameter. - {{% badge style="note" title=" " %}}Change{{% /badge %}} The [`tabs` shortcode]({{% relref "shortcodes/tabs" %}}) has changed behavior if you haven't set the `groupid` parameter.

View file

@ -1,36 +0,0 @@
+++
tags = ["documentation", "tutorial stuff"]
title = "Tags"
weight = 7
+++
The Relearn theme supports one default taxonomy of Hugo: the *tag* feature.
## Configuration
Just add tags to any page:
```toml
+++
tags = ["tutorial", "theme"]
title = "Theme tutorial"
weight = 15
+++
```
## Behavior
The tags are displayed at the top of the page, in their insertion order.
Each tag is a link to a *Taxonomy* page displaying all the articles with the given tag.
## List all the tags
In the `config.toml` file you can add a shortcut to display all the tags
```toml
[[menu.shortcuts]]
name = "<i class='fas fa-tags'></i> Tags"
url = "/tags"
weight = 30
```

View file

@ -1,6 +0,0 @@
+++
tags = ["documentat'n", "tutorrrial"]
title = "Tags"
weight = 7
+++
{{< piratify >}}

View file

@ -0,0 +1,42 @@
+++
categories = ["taxonomy", "content"]
tags = "tutorial"
title = "Taxonomy"
weight = 7
+++
The Relearn theme supports Hugo's default taxonomies *tag* and *category* out of the box.
## Configuration
Just add tags and/or categories to any page. They can be given as a single string or an array of strings.
```toml
+++
categories = ["taxonomy", "content"]
tags = "tutorial"
title = "Taxonomy"
+++
```
## Behavior
The tags are displayed at the top of the page in alphabetical order.
The categories are displayed at the bottom of the page in alphabetical order in the default implementation of the theme but can be customized by providing your own `content-footer.html` partial.
Each item is a link to a taxonomy page displaying all the articles with the given term.
## List all the tags
In the `config.toml` file you can add a shortcut to display all the tags and categories
```toml
[[menu.shortcuts]]
name = "<i class='fas fa-tags'></i> Tags"
url = "/tags"
[[menu.shortcuts]]
name = "<i class='fas fa-list'></i> Categories"
url = "/categories"
```

View file

@ -0,0 +1,7 @@
+++
categories = ["taxonomy", "content"]
tags = "tutorrrial"
title = "Taxonomy"
weight = 7
+++
{{< piratify >}}

View file

@ -3,4 +3,15 @@
{{- with $.Date }} {{- with $.Date }}
<i class='fas fa-calendar'></i> {{ . | time.Format ":date_medium" }} <i class='fas fa-calendar'></i> {{ . | time.Format ":date_medium" }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- $page := . }}
{{- if .Params.categories }}
<i class='fas fa-list'></i>
{{- $categories := slice | append .Params.categories }}
{{- range $idx, $category := sort $categories }}
{{- with $page.Site.GetPage (printf "%s%s" ("/categories/" | relURL ) ( $category | anchorize ) ) }}
{{- $to := . }}
{{ if gt $idx 0 }} | {{ end }}<a class="tag-link" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }}">{{ $category }}</a>
{{- end }}
{{- end }}
{{- end }}

View file

@ -2,12 +2,13 @@
{{- $page := . }} {{- $page := . }}
{{- if .Params.tags }} {{- if .Params.tags }}
<div class="tags"> <div class="tags">
{{- range sort .Params.tags }} {{- $tags := slice | append .Params.tags }}
{{- $tag := . }} {{- range sort $tags }}
{{- with $page.Site.GetPage (printf "%s%s" ("/tags/" | relURL ) ( $tag | anchorize ) ) }} {{- $tag := . }}
{{- $to := . }} {{- with $page.Site.GetPage (printf "%s%s" ("/tags/" | relURL ) ( $tag | anchorize ) ) }}
{{- $to := . }}
<a class="tag-link" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }}">{{ $tag }}</a> <a class="tag-link" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }}">{{ $tag }}</a>
{{- end }}
{{- end }} {{- end }}
{{- end }}
</div> </div>
{{- end }} {{- end }}