hugo-theme-fha/layouts/partials/cloudtag.html

31 lines
1.4 KiB
HTML

{{ if not (eq (len $.Site.Taxonomies.tags) 0) }}
{{ $fontUnit := "rem" }}
{{ $largestFontSize := 2.0 }}
{{ $largestFontSize := 2.5 }}
{{ $smallestFontSize := 0.8 }}
{{ $fontSpread := sub $largestFontSize $smallestFontSize }}
{{ $max := add (len (index $.Site.Taxonomies.tags.ByCount 0).Pages) 1 }}
{{ $min := len (index $.Site.Taxonomies.tags.ByCount.Reverse 0).Pages }}
{{ $spread := sub $max $min }}
{{ $fontStep := div $fontSpread $spread }}
<div id="tag-cloud col" class="card" style="margin:0;padding:0;">
<div class="card-header card-titl text-bg-secondary mb-3">
<h3>Tags</h3>
</div>
<div class="card-body card-text" style="margin:0;padding:0.4em;text-align: center;">
{{ range $name, $taxonomy := $.Site.Taxonomies.tags }}
{{ $currentTagCount := len $taxonomy.Pages }}
{{ $currentFontSize := (add $smallestFontSize (mul (sub $currentTagCount $min) $fontStep) ) }}
{{ $count := len $taxonomy.Pages }}
{{ $weigth := div (sub (math.Log $count) (math.Log $min)) (sub (math.Log $max) (math.Log $min)) }}
{{ $currentFontSize := (add $smallestFontSize (mul (sub $largestFontSize $smallestFontSize) $weigth) ) }}
<!--Current font size: {{$currentFontSize}}-->
<a href="{{ "tags/" | relLangURL }}{{ $name | urlize }}"
style="font-size:{{$currentFontSize}}{{$fontUnit}}" class="text-decoration-none">{{ $name }}</a>
{{ end }}
</div>
</div>
{{ end }}