Skip to content

Instantly share code, notes, and snippets.

@kokodev

kokodev/tag-cloud.html Secret

Last active Jun 16, 2020
Embed
What would you like to do?
Tag cloud code for a Hugo theme
<div class="sidepanel">
<div class="box tags">
<div class="tagcloud">
{{ $weights := 10 }}
{{ $tags := $.Site.Taxonomies.categories.ByCount }}
{{ range $key, $value := $tags }}
{{ $.Scratch.Add $value.Name $value.Count }}
{{ $.Scratch.SetInMap "buckets" (string $value.Count) $value.Count }}
{{ end }}
{{ range $index, $value := $.Site.Taxonomies.categories.Alphabetical }}
<span
{{ $buckets := $.Scratch.GetSortedMapValues "buckets" }}
{{ range $bucketIndex, $bucketEntry := sort $buckets }}
{{ $val := ($.Scratch.Get $value.Name) }}
{{ if eq $bucketEntry $val }}
{{ if ge (sub (sub (len $buckets) 1) $bucketIndex) 0 }}
{{ $backIndex := sub (sub (len $buckets) 1) $bucketIndex }}
{{ $weight := sub $weights $backIndex }}
{{ if ge $weight 1 }}
class="weight-{{ $weight }}"
{{ else }}
class="weight-0"
{{ end }}
{{ else }}
class="weight-0"
{{ end }}
{{ end }}
{{ end }}>
<a href="/tags/{{ $value.Name | urlize }}">{{ lower (humanize $value.Name) }}</a>
</span>
{{ end }}
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.