Skip to content

Commit b202968

Browse files
yuri1969imfing
authored andcommitted
feat(tags): improve usability of tags (#698)
* feat(tags): improve usability of tags * Tags can be shown also at docs * Documented tag-related config flags * Added example tags to the site * Made rendered tags active * Move tags listing to ToC * Hide tags section on no tags
1 parent 21374fa commit b202968

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

exampleSite/content/docs/getting-started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
title: Getting Started
33
weight: 1
4+
tags:
5+
- Docs
6+
- Guide
47
next: /docs/guide
58
prev: /docs
69
---

exampleSite/content/docs/guide/configuration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: Configuration
33
weight: 2
4+
tags:
5+
- Config
46
---
57

68
Hugo reads its configuration from `hugo.yaml` in the root of your Hugo site.
@@ -228,6 +230,19 @@ params:
228230
dateFormat: "January 2, 2006"
229231
```
230232

233+
### Tags
234+
235+
To display page tags, set following flags in the config file:
236+
237+
```yaml {filename="hugo.yaml"}
238+
params:
239+
blog:
240+
list:
241+
displayTags: true
242+
toc:
243+
displayTags: true
244+
```
245+
231246
### Page Width
232247

233248
The width of the page can be customized by the `params.page.width` parameter in the config file:

exampleSite/hugo.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ params:
174174
article:
175175
displayPagination: true
176176

177+
toc:
178+
displayTags: true
179+
177180
highlight:
178181
copy:
179182
enable: true

layouts/_partials/tags.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p class="hx:opacity-50 hx:text-sm hx:leading-7">
2+
{{- range $tag := .Params.tags -}}
3+
{{- with $.Site.GetPage (printf "/tags/%s" $tag) -}}
4+
<a class="hx:inline-block hx:mr-2" href="{{ .RelPermalink }}">#{{ .Title }}</a>
5+
{{- end -}}
6+
{{- end -}}
7+
</p>

layouts/_partials/toc.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{/* TODO: toc bottom part should be able to hide */}}
33
{{- $toc := .Params.toc | default true -}}
44
{{- $onThisPage := (T "onThisPage") | default "On this page"}}
5+
{{- $tags := (T "tags") | default "Tags"}}
56
{{- $editThisPage := (T "editThisPage") | default "Edit this page"}}
67
{{- $backToTop := (T "backToTop") | default "Scroll to top" -}}
78

@@ -18,6 +19,14 @@
1819
{{- end -}}
1920

2021
{{- $borderClass := "hx:mt-8 hx:border-t hx:bg-white hx:pt-8 hx:shadow-[0_-12px_16px_white] hx:dark:bg-dark hx:dark:shadow-[0_-12px_16px_#111]" -}}
22+
23+
{{- if and site.Params.toc.displayTags .Params.tags -}}
24+
<div class="{{ $borderClass }} hx:sticky hx:bottom-0 hx:flex hx:flex-col hx:items-start hx:gap-2 hx:border-gray-200 hx:dark:border-neutral-800 hx:contrast-more:border-t hx:contrast-more:border-neutral-400 hx:contrast-more:shadow-none hx:contrast-more:dark:border-neutral-400">
25+
<p class="hx:mb-1 hx:font-semibold hx:tracking-tight">{{ $tags }}</p>
26+
{{ partial "tags.html" . }}
27+
</div>
28+
{{- end -}}
29+
2130
{{- if not .Fragments.Headings -}}
2231
{{- $borderClass = "" -}}
2332
{{- end -}}

layouts/blog/list.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
{{- range $pages }}
1212
<div class="hx:mb-10">
1313
<h3><a style="color: inherit; text-decoration: none;" class="hx:block hx:font-semibold hx:mt-8 hx:text-2xl " href="{{ .RelPermalink }}">{{ .Title }}</a></h3>
14-
{{- if site.Params.blog.list.displayTags -}}
15-
{{ with .Params.tags }}
16-
<p class="hx:opacity-50 hx:text-sm hx:leading-7">
17-
{{- range . }}<a class="hx:inline-block hx:mr-2">#{{ . }}</a>{{ end -}}
18-
</p>
19-
{{ end -}}
20-
{{- end -}}
14+
{{ if site.Params.blog.list.displayTags }}
15+
{{ partial "tags.html" . }}
16+
{{ end }}
2117
<p class="hx:opacity-80 hx:mt-4 hx:leading-7">{{- partial "utils/page-description" . -}}</p>
2218
<p class="hx:opacity-80 hx:mt-1 hx:leading-7">
2319
<a class="hx:text-[color:hsl(var(--primary-hue),100%,50%)] hx:underline hx:underline-offset-2 hx:decoration-from-font" href="{{ .RelPermalink }}">

0 commit comments

Comments
 (0)