Ronalds Vilciņš

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.

Go HTML template
{{ $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.

Filed under on

← Back to all articles