mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-13 18:15:09 +00:00
feat: add max count option to Tags widget
Choose how many tags you would like to display.
This commit is contained in:
1 parent
32b6145c06
commit
d0ec05a65b
2 files changed
+19
-7
No files matched your search
@@ -7,4 +7,8 @@ weight = 120 # Order that this section will appear.
|
|||||||
|
|
||||||
title = "Popular Topics"
|
title = "Popular Topics"
|
||||||
subtitle = ""
|
subtitle = ""
|
||||||
|
|
||||||
|
[content]
|
||||||
|
# Choose how many tags you would like to display (0 = all tags)
|
||||||
|
count = 20
|
||||||
+++
|
+++
|
||||||
@@ -1,26 +1,34 @@
|
|||||||
{{ $ := .root }}
|
{{ $ := .root }}
|
||||||
{{ $page := .page }}
|
{{ $st := .page }}
|
||||||
|
|
||||||
|
{{ $items_count := $st.Params.content.count }}
|
||||||
|
{{ if eq $items_count 0 }}
|
||||||
|
{{ $items_count = 65535 }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $items_count = $items_count | default 20 }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-lg-4 section-heading">
|
<div class="col-12 col-lg-4 section-heading">
|
||||||
<h1>{{ with $page.Title }}{{ . | markdownify | emojify }}{{ end }}</h1>
|
<h1>{{ with $st.Title }}{{ . | markdownify | emojify }}{{ end }}</h1>
|
||||||
{{ with $page.Params.subtitle }}<p>{{ . | markdownify | emojify }}</p>{{ end }}
|
{{ with $st.Params.subtitle }}<p>{{ . | markdownify | emojify }}</p>{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-lg-8">
|
<div class="col-12 col-lg-8">
|
||||||
{{ with $page.Content }}{{ . }}{{ end }}
|
{{ with $st.Content }}{{ . }}{{ end }}
|
||||||
|
|
||||||
{{ if not (eq (len site.Taxonomies.tags) 0) }}
|
{{ if not (eq (len site.Taxonomies.tags) 0) }}
|
||||||
|
{{ $tags := first $items_count site.Taxonomies.tags.ByCount }}
|
||||||
{{ $fontSmall := 0.8 }}
|
{{ $fontSmall := 0.8 }}
|
||||||
{{ $fontBig := 2.5 }}
|
{{ $fontBig := 2.5 }}
|
||||||
|
|
||||||
{{ $fontDelta := sub $fontBig $fontSmall }}
|
{{ $fontDelta := sub $fontBig $fontSmall }}
|
||||||
{{ $min := len (index site.Taxonomies.tags.ByCount.Reverse 0).Pages }}
|
{{ $min := len (index ($tags).Reverse 0).Pages }}
|
||||||
{{ $max := add (len (index site.Taxonomies.tags.ByCount 0).Pages) 1 }}
|
{{ $max := add (len (index $tags 0).Pages) 1 }}
|
||||||
{{ $delta := sub $max $min }}
|
{{ $delta := sub $max $min }}
|
||||||
{{ $fontStep := div $fontDelta $delta }}
|
{{ $fontStep := div $fontDelta $delta }}
|
||||||
|
|
||||||
<div class="tag-cloud">
|
<div class="tag-cloud">
|
||||||
{{ range $name, $taxonomy := site.Taxonomies.tags }}
|
{{ range $name, $taxonomy := $tags }}
|
||||||
{{ $tagCount := len $taxonomy.Pages }}
|
{{ $tagCount := len $taxonomy.Pages }}
|
||||||
{{ $weight := div (sub (math.Log $tagCount) (math.Log $min)) (sub (math.Log $max) (math.Log $min)) }}
|
{{ $weight := div (sub (math.Log $tagCount) (math.Log $min)) (sub (math.Log $max) (math.Log $min)) }}
|
||||||
{{ $fontSize := add $fontSmall (mul (sub $fontBig $fontSmall) $weight) }}
|
{{ $fontSize := add $fontSmall (mul (sub $fontBig $fontSmall) $weight) }}
|
||||||
|
|||||||
Reference in new issue
Block a user