dsrkafuu / hugo-theme-fuji

A minimal Hugo theme with nice theme color. | 一个主题色极简 Hugo 主题。
https://github.dsrkafuu.net/hugo-theme-fuji/
Apache License 2.0
368 stars 98 forks source link

[Feature Request] Tag Cloud #53

Closed FelixBenning closed 3 years ago

FelixBenning commented 4 years ago

The minimo theme had this nice idea of resizing the tags in the taglist by the relative number of occurances.

I am not sure how copyable this is:

taxonomy_cloud.html from minimo (MIT Licence so that should be fine)

{{- $Scope := .Scope -}}
{{- $Site := $Scope.Site -}}
{{- $Scratch := $Scope.Scratch -}}
{{- $Shuffle := ( .Shuffle | default true ) -}}
{{- $TaxonomyPage := ( $Site.GetPage ( print "/" .Taxonomy ) ) -}}
{{- $Data := $TaxonomyPage.Data -}}

<div class='container list-container'>
  <ul class='list taxonomy-cloud {{- if not $Shuffle }} no-shuffle {{- end -}}'>
  {{- if gt ( len $Data.Terms ) 0 -}}
    {{- $maxSize := 2.0 -}}
    {{- $minSize := 1.0 -}}
    {{- $sizeSpread := ( sub $maxSize $minSize ) -}}

    {{- $maxCount := ( index $Data.Terms.ByCount 0 ).Count -}}
    {{- $minCount := ( index $Data.Terms.ByCount.Reverse 0 ).Count -}}
    {{- $countSpread := ( sub $maxCount $minCount ) -}}

    {{- $Scratch.Set "sizeStep" 0 -}}
    {{- if gt $countSpread 0 -}}
      {{- $Scratch.Set "sizeStep" ( div $sizeSpread $countSpread ) -}}
    {{- end -}}

    {{- range $Data.Terms.Alphabetical -}}
      {{- $count := .Count -}}
      {{- $sizeStep := ( $Scratch.Get "sizeStep" ) -}}
      {{- $size := ( add $minSize ( mul $sizeStep ( sub $count $minCount ) ) ) -}}

      <li>
        <a href='{{ .Page.RelPermalink }}' style='font-size:{{ $size }}em'>
          {{- .Page.Title -}}
        </a>
      </li>
    {{- end -}}
  {{- else -}}
    <span>
      {{- $term := ( ( ( i18n $Data.Singular 1 ) | default $Data.Singular ) ) -}}
      {{- i18n "noTerm" ( dict "Term" $term ) -}}
    </span>
  {{- end -}}
  </ul>
</div>

the end result looks like this:

grafik

dsrkafuu commented 4 years ago

This feature doesn't quite fit the theme's goals, although perhaps you can create overlay templates on your own site to try it out!