better tagcloud #328

Merged
paspo merged 1 commits from paspo/bglug.it:better-tagcloud into main 2024-10-31 22:08:47 +00:00
2 changed files with 23 additions and 22 deletions

View File

@ -211,6 +211,22 @@ article header div.author {
}
.tags-sidebar {
--font_min_rem: 16px;
--font_max_rem: 32px;
--delta: calc(var(--font_max_rem) - var(--font_min_rem));
a.font-size-0 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.0 ); }
a.font-size-1 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.1 ); }
a.font-size-2 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.2 ); }
a.font-size-3 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.3 ); }
a.font-size-4 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.4 ); }
a.font-size-5 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.5 ); }
a.font-size-6 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.6 ); }
a.font-size-7 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.7 ); }
a.font-size-8 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.8 ); }
a.font-size-9 { font-size: calc(var(--font_min_rem) + var(--delta) * 0.9 ); }
a.font-size-10 { font-size: calc(var(--font_min_rem) + var(--delta) * 1.0 ); }
li.hidden {
display: none;
visibility: hidden;

View File

@ -7,46 +7,31 @@
{{ $count_min_display := 3 }}
{{ $tags := where .Site.Taxonomies.tags ".Page.Section" .Section }}
{{ $count := len $tags }}
{{ $count_min := -1 }}
{{ $count_max := -1 }}
{{/* attenzione: $num_fonts deve essere float, quindi specificare sempre i decimali */}}
{{ $num_fonts := 10.0 }}
{{ 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 }}
{{ if lt $count_min $count_min_display }}
{{ $count_min = $count_min_display }}
{{ if le $count_max 0 }}
{{ $count_max = 1 }}
{{ end }}
{{ if le $count_max $count_min }}
{{ $count_max = add $count_min 1 }}
{{ 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 }}
{{ $font_size := (add $font_min (mul $c $font_step)) }}
{{ $font_size := int ( mul $c (div $num_fonts $count_max) ) }}
{{ if ge $c $count_min_display }}
<li>
<a style="font-size: {{ $font_size }}rem;" href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }} ({{ len .Pages }})</a></li>
<a class="font-size-{{ $font_size }}" href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }} ({{ len .Pages }})</a></li>
{{ else }}
<li class="hidden">
<a style="font-size: {{ $font_size }}rem;" href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }} ({{ len .Pages }})</a></li>
<a class="font-size-{{ $font_size }}" href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }} ({{ len .Pages }})</a></li>
{{ end }}
{{ end }}
<li><a id="more-tags">{{ T "more_tags" }}</a></li>