1
0
forked from BgLUG/bglug.it

tag cloud con font size variabile e soglia minima (#247)

#232

attenzione!! conflitta con #246!! accettarne solo una delle due!

Reviewed-on: BgLUG/bglug.it#247
Co-authored-by: paspo <paolo@asperti.com>
Co-committed-by: paspo <paolo@asperti.com>
This commit is contained in:
Paolo Asperti 2024-09-23 20:09:40 +00:00 committed by Paolo Asperti
parent 3e30daef1d
commit 1d6d44a0cd
3 changed files with 56 additions and 4 deletions

View File

@ -9,3 +9,4 @@ subscribe_mailinglist: Subscribe to our mailing list
subscribe: Subscribe
come_and_see_us: Come and see us
where: Where
more_tags: "...more"

View File

@ -9,3 +9,4 @@ subscribe_mailinglist: Iscriviti alla mailing list
subscribe: Iscriviti
come_and_see_us: Vieni a trovarci
where: Dove siamo
more_tags: "...altro"

View File

@ -1,11 +1,61 @@
<section>
<script>
function show_all_tags(e) {
$(".tags-sidebar li").css("display","inline-block");
$(e).css("display","none");
return false;
}
</script>
{{- $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 }}
{{ $font_size := (add $font_min (mul $c $font_step)) }}
{{ 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>
{{ else }}
<li style="display: none;">
<a style="font-size: {{ $font_size }}rem;" href="/{{ .Page.Lang }}{{ .Page.Path }}">{{ .Page.LinkTitle | safeHTML }} ({{ len .Pages }})</a></li>
{{ end }}
{{ end }}
<li><a href="#" onclick="return show_all_tags(this)">{{ T "more_tags" }}</a></li>
</ul>
</section>