A simple tag cloud for Hugo
This is a compact tag cloud for a Hugo site. It lists tags by count, keeps only tags used at least three times, and excludes a few terms that I do not want in the result.
{{ $tags := $.Site.Taxonomies.tags.ByCount }}
{{ $v1 := where $tags "Count" ">=" 3 }}
{{ $v2 := where $v1 "Term" "not in" (slice "hugo" "tags" "rss") }}
{{ range $v2 }}
{{ if .Term }}
{{ $tagURL := printf "tags/%s" .Term | relURL }}
<a href="{{ $tagURL }}">{{ .Term }} ({{ .Count }})</a>
{{ end }}
{{ end }}
Change 3 to control the minimum number of posts. The slice containing "hugo", "tags", and "rss" is the exclusion list, so replace those values with terms that make sense for your site.
This outputs plain links and counts. I prefer to handle spacing, size, and colour in CSS rather than make the template responsible for presentation.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- When to Use Hugo Shortcodes or Render Hooks
Use render hooks to change normal Markdown output and shortcodes for custom content with meaning Markdown cannot express.
- Customizing Hugo’s RSS Feed
Adjust Hugo RSS titles, descriptions, content, and section filtering while keeping the generated feed valid and easy to discover.
- Organizing Hugo Content With Tags and Categories
Organize Hugo content with a small, deliberate set of tags, categories, or custom taxonomies that lead to useful archive pages.