tag cloud con font size variabile e soglia minima #247

Merged
paspo merged 3 commits from paspo/bglug.it:taglist_advanced into main 2024-09-23 20:09:40 +00:00
Showing only changes of commit cb64ffe02c - Show all commits

View File

@ -2,10 +2,47 @@
{{- $hiddenTags := slice "Linuxday-Featured" -}}
<h3>Tags</h3>
<ul class="tags-sidebar">
{{ range where .Site.Taxonomies.tags ".Page.Section" .Section }}
{{ if not (in $hiddenTags .Page.LinkTitle ) }}
<li><a href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }}</a></li>
{{ $font_min := 1.0 }}
{{ $font_max := 3.5 }}
{{ $count_min_display := 3 }}
{{ $tags := where .Site.Taxonomies.tags ".Page.Section" .Section }}
{{ $tags := where $tags ".Page.LinkTitle" "not in" $hiddenTags }}
{{ $count := len $tags }}
{{ $count_min := -1 }}
{{ $count_max := -1 }}
{{ range $tags }}
{{ $c := len .Pages }}
{{ if gt $c $count_max }}
{{ $count_max = $c }}
{{ end }}
{{ if le $count_min -1 }}
{{ $count_min = $c }}
{{ end }}
{{ if lt $c $count_min }}
{{ $count_min = $c }}
{{ end }}
{{ end }}
</ul>
{{ if lt $count_min $count_min_display }}
{{ $count_min = $count_min_display }}
{{ end }}
{{ $count_delta := sub $count_max $count_min }}
{{ $font_delta := sub $font_max $font_min }}
{{ $font_step := div $font_delta $count_delta }}
{{/* range $tags.ByCount */}}
{{ range $tags.Alphabetical }}
{{ $c := len .Pages }}
{{ if ge $c $count_min_display }}
{{ $font_size := (add $font_min (mul $c $font_step)) }}
<li style="font-size: {{ $font_size }}rem;">
<a href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }}</a><sup>{{ len .Pages }}</sup></li>
{{ end }}
{{ end }}
</ul>
</section>