Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tag_cloud.html « _widgets « partials « layouts - github.com/xiaoheiAh/hugo-theme-pure.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 21b089426d0ed5c20bfc13ae619fb541c43fb8e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<div class="widget">
    <h3 class="widget-title"> {{ T "widget_tags" }}</h3>
    <div id="tag-cloud-list" class="widget-body">
            {{ range $name, $taxonomy := $.Site.Taxonomies.tags }}
            {{ with $.Site.GetPage (printf "/tags/%s" $name) }}
            <a href="{{ .Permalink }}" class="tag-list-link" rel="{{ $taxonomy.Count}}">{{ $name }}<span
               class="tag-list-count">{{ $taxonomy.Count}}</span></a>
            {{ end }}
            {{- end }}
    </div>
<script>
document.onreadystatechange = () => {
  if (document.readyState === 'complete') {
    tagCloud('#tag-cloud-list a', {{ $.Site.Params.tag_cloud.min }}, {{ $.Site.Params.tag_cloud.max }});
  }
};

function tagCloud(where, min, max) {
  let iMax = 0;
  let iMin = 0;
  $(where).each(function() {
    let weight = Number($(this).attr("rel"));
    if(iMax < weight) iMax = weight;
    if(iMin > weight || iMin == 0) iMin = weight;
  });
  let step = (max - min)/(iMax - iMin);
  $(where).each(function() {
    let weight = $(this).attr("rel") - iMin;
    $(this).css({"font-size": min + (weight * step) + 'px'});
  });
};
</script>
</div>