Skip to content

Commit a666aa5

Browse files
authored
Merge pull request #2852 from MaikelChan/badges
✨ Implemented category badges in secondary color and better granularity for showing categories or tags
2 parents 89e261f + 167ee1f commit a666aa5

5 files changed

Lines changed: 69 additions & 24 deletions

File tree

assets/css/compiled/main.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,9 +1669,15 @@
16691669
.border-primary-500 {
16701670
border-color: rgba(var(--color-primary-500), 1);
16711671
}
1672+
.border-secondary-400 {
1673+
border-color: rgba(var(--color-secondary-400), 1);
1674+
}
16721675
.border-secondary-500 {
16731676
border-color: rgba(var(--color-secondary-500), 1);
16741677
}
1678+
.border-secondary-600 {
1679+
border-color: rgba(var(--color-secondary-600), 1);
1680+
}
16751681
.border-transparent {
16761682
border-color: transparent;
16771683
}
@@ -2184,6 +2190,12 @@
21842190
.text-primary-800 {
21852191
color: rgba(var(--color-primary-800), 1);
21862192
}
2193+
.text-secondary-400 {
2194+
color: rgba(var(--color-secondary-400), 1);
2195+
}
2196+
.text-secondary-700 {
2197+
color: rgba(var(--color-secondary-700), 1);
2198+
}
21872199
.text-transparent {
21882200
color: transparent;
21892201
}
@@ -3271,6 +3283,16 @@
32713283
border-color: rgba(var(--color-primary-600), 1);
32723284
}
32733285
}
3286+
.dark\:border-secondary-600 {
3287+
&:is(.dark *) {
3288+
border-color: rgba(var(--color-secondary-600), 1);
3289+
}
3290+
}
3291+
.dark\:border-secondary-800 {
3292+
&:is(.dark *) {
3293+
border-color: rgba(var(--color-secondary-800), 1);
3294+
}
3295+
}
32743296
.dark\:border-white\/10 {
32753297
&:is(.dark *) {
32763298
border-color: color-mix(in oklab, #fff 10%, transparent);
@@ -3500,6 +3522,16 @@
35003522
color: rgba(var(--color-primary-400), 1);
35013523
}
35023524
}
3525+
.dark\:text-secondary-200 {
3526+
&:is(.dark *) {
3527+
color: rgba(var(--color-secondary-200), 1);
3528+
}
3529+
}
3530+
.dark\:text-secondary-400 {
3531+
&:is(.dark *) {
3532+
color: rgba(var(--color-secondary-400), 1);
3533+
}
3534+
}
35033535
.dark\:text-white {
35043536
&:is(.dark *) {
35053537
color: #fff;

config/_default/params.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ forgejoDefaultServer = "https://v11.next.forgejo.org"
8787
showTableOfContents = false
8888
# showRelatedContent = false
8989
# relatedContentLimit = 3
90-
showTaxonomies = false # use showTaxonomies OR showCategoryOnly, not both
91-
showCategoryOnly = false # use showTaxonomies OR showCategoryOnly, not both
90+
showTaxonomies = false # Enable the display of taxonomies for the related article.
91+
showCategories = true # These will show if showTaxonomies is true.
92+
showTags = true # These will show if showTaxonomies is true.
93+
showCategoriesInSecondaryColor = false # This will change the color of category badges, so the user can better distinguish between the two. Only if showTaxonomies is true.
9294
showAuthorsBadges = false
9395
showWordCount = true
9496
# sharingLinks = [ "linkedin", "twitter", "bluesky", "mastodon", "reddit", "pinterest", "facebook", "email", "whatsapp", "telegram", "line"]

exampleSite/content/docs/configuration/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ Many of the article defaults here can be overridden on a per article basis by sp
261261
| `article.showRelatedContent` | `false` | Display related content for each post. Might required additional configuration to your `hugo.toml`. Please check the theme `hugo.toml` if you want to enable this feature and copy all the relevant _related_ entries. Also check [Hugo's docs](https://gohugo.io/content-management/related/) on related content. |
262262
| `article.relatedContentLimit` | `3` | Limit of related articles to display if `showRelatedContent` is turned on. |
263263
| `article.showTaxonomies` | `false` | Whether or not all the taxonomies related to this article are displayed. |
264-
| `article.showCategoryOnly` | `false` | Whether or not the "category" taxonomy is displayed. `showTaxonomies` should be `false` when this param is used, otherwise duplicates will appear. |
264+
| `article.showCategories` | `true` | Whether or not the `category` taxonomies are displayed. Requires `showTaxonomies` to be `true`. |
265+
| `article.showTags` | `true` | Whether or not the `tag` taxonomies are displayed. Requires `showTaxonomies` to be `true`. |
266+
| `article.showCategoriesInSecondaryColor` | `false` | This will make the `category` taxonomy badges to show in a secondary color, so the user can better distinguish between categories and tags. Requires `showTaxonomies` to be `true`. |
265267
| `article.showAuthorsBadges` | `false` | Whether the `authors` taxonomies are are displayed in the article or list header. This requires the setup of `multiple authors` and the `authors` taxonomy. Check [this page]({{< ref "multi-author" >}}) for more details on how to configure that feature. |
266268
| `article.showWordCount` | `false` | Whether or not article word counts are displayed. |
267269
| `article.showComments` | `false` | Whether or not the [comments partial]({{< ref "partials#comments" >}}) is included after the article footer. |

layouts/partials/article-meta/basic.html

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,26 @@
9898
{{ if .Params.showTaxonomies | default (.Site.Params.article.showTaxonomies | default false) }}
9999
<div class="flex flex-row flex-wrap items-center">
100100
{{ range $taxonomy, $terms := .Site.Taxonomies }}
101-
{{ if and (not (eq $taxonomy "authors")) (not (eq $taxonomy "series")) }}
102-
{{ if (gt (len ($context.GetTerms $taxonomy)) 0) }}
103-
{{ range $context.GetTerms $taxonomy }}
104-
<a class="relative mt-[0.5rem] me-2" href="{{ .RelPermalink }}">
105-
{{ partial "badge.html" .LinkTitle }}
106-
</a>
101+
{{ if (gt (len ($context.GetTerms $taxonomy)) 0) }}
102+
{{ range $context.GetTerms $taxonomy }}
103+
{{ if .Params.showCategories | default (.Site.Params.article.showCategories | default true) }}
104+
{{ if (eq $taxonomy "categories") }}
105+
<a class="relative mt-[0.5rem] me-2" href="{{ .RelPermalink }}">
106+
{{ $useSecondaryColor := .Params.showCategoriesInSecondaryColor | default (.Site.Params.article.showCategoriesInSecondaryColor | default false) }}
107+
{{ partial "badge.html" (dict "linkTitle" .LinkTitle "useSecondaryColor" $useSecondaryColor) }}
108+
</a>
109+
{{ end }}
110+
{{ end }}
111+
{{ if .Params.showTags | default (.Site.Params.article.showTags | default true) }}
112+
{{ if (eq $taxonomy "tags") }}
113+
<a class="relative mt-[0.5rem] me-2" href="{{ .RelPermalink }}">
114+
{{ partial "badge.html" .LinkTitle }}
115+
</a>
116+
{{ end }}
107117
{{ end }}
108118
{{ end }}
109119
{{ end }}
110120
{{ end }}
111121
</div>
112122
{{ end }}
113-
114-
{{/* Output only category */}}
115-
{{ if .Params.showCategoryOnly | default (.Site.Params.article.showCategoryOnly | default false) }}
116-
<div class="flex flex-row flex-wrap items-center">
117-
{{ range (.GetTerms "categories") }}
118-
<a class="relative mt-[0.5rem] me-2" href="{{ .RelPermalink }}">
119-
{{ partial "badge.html" .LinkTitle }}
120-
</a>
121-
{{ end }}
122-
</div>
123-
{{ end }}
124-
125123
{{ end }}

layouts/partials/badge.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<span class="flex cursor-pointer">
2-
<span
3-
class="rounded-md border border-primary-400 px-1 py-[1px] text-xs font-normal text-primary-700 dark:border-primary-600 dark:text-primary-400">
4-
{{ . }}
2+
{{ $linkTitle := . }}
3+
{{ $useSecondaryColor := false }}
4+
{{ if (reflect.IsMap . ) }}
5+
{{ $linkTitle = .linkTitle }}
6+
{{ $useSecondaryColor = cond (not .useSecondaryColor) false .useSecondaryColor }}
7+
{{ end }}
8+
{{ if $useSecondaryColor }}
9+
<span
10+
class="rounded-md border border-secondary-400 px-1 py-[1px] text-xs font-normal text-secondary-700 dark:border-secondary-600 dark:text-secondary-400">
11+
{{ else }}
12+
<span
13+
class="rounded-md border border-primary-400 px-1 py-[1px] text-xs font-normal text-primary-700 dark:border-primary-600 dark:text-primary-400">
14+
{{ end }}
15+
{{ $linkTitle }}
516
</span>
617
</span>

0 commit comments

Comments
 (0)