-
-
Save kokodev/ae9bb1bacef2ea1428a59bada3c76b5d to your computer and use it in GitHub Desktop.
Tag cloud code for a Hugo theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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