{{- define "title" -}}
  {{- .Params.Title | default (T .Data.Plural) | default .Data.Plural | dict "Some" | T "allSome" }} - {{ .Site.Title -}}
{{- end -}}

{{- define "content" -}}
  {{- $taxonomies := .Data.Plural -}}
  {{- $terms := .Data.Terms.ByCount -}}
  {{- $type := .Type -}}

  <div class="page archive">
    {{- /* Title */ -}}
    <h2 class="single-title animate__animated animate__pulse animate__faster">
      {{- .Params.Title | default (T $taxonomies) | default $taxonomies | dict "Some" | T "allSome" }}
      <sup>{{- len $terms -}}</sup>
    </h2>

    {{- /* Categories Page */ -}}
    {{- if eq $taxonomies "categories" -}}
      <div class="categories-card">
        {{- range $terms -}}
          {{- $term := .Term -}}
          {{- $pages := .Pages -}}
          {{- with $.Site.GetPage "taxonomy" (printf "%v/%v" $type $term) -}}
          <div class="card-item">
            <div class="card-item-wrapper">
              <h3 class="card-item-title">
                <a href='{{ replace .RelPermalink "#" "%23" }}'>
                  {{ dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html" }}
                  {{ .Page.Title }}&nbsp;<sup>{{- len $pages -}}</sup>
                </a>
              </h3>
              {{- range first 5 $pages -}}
                <article class="archive-item">
                  <a href="{{ .RelPermalink }}" class="archive-item-link">{{- .Title -}}</a>
                </article>
              {{- end -}}
              {{- if gt (len $pages) 5 -}}
                <span class="more-post">
                  <a href='{{ replace .RelPermalink "#" "%23" }}' class="more-single-link">{{ T "more" }} >></a>
                </span>
              {{- end -}}
            </div>
          </div>
          {{- end -}}
        {{- end -}}
      </div>

    {{- /* Tag Cloud Page */ -}}
    {{- else if eq $taxonomies "tags" -}}
      {{- $tagCloud := .Site.Params.tagcloud -}}
      <div class="tag-cloud-tags{{ with $tagCloud.enable }} text-center{{ end }}">
        {{- if $tagCloud.enable -}}
          {{- $tags := cond (eq $tagCloud.orderby "name") $.Site.Taxonomies.tags.Alphabetical $.Site.Taxonomies.tags.ByCount -}}
          {{- $baseGrade := div ($tagCloud.peakCount | default 10) 10.0 -}}
          {{- $minFont := $tagCloud.min | default 16 -}}
          {{- $baseFont := div (sub ($tagCloud.max | default 32) $minFont) 10.0 -}}
          {{- range $tags -}}
            {{- $grade := math.Min (math.Floor (div (sub .Count 1) $baseGrade)) 10 -}}
            {{- $fontSize := add $minFont (mul $grade $baseFont) -}}
            <a href='{{ replace .Page.RelPermalink "#" "%23" }}' class="tag-cloud-{{ $grade }}" style="--tag-font: {{ $fontSize }}px">{{ .Page.Title }} <sup>{{ .Count }}</sup></a>
          {{- end -}}
        {{- else -}}
          {{- range $.Site.Taxonomies.tags.ByCount -}}
            <a href='{{ replace .Page.RelPermalink "#" "%23" }}'>{{ .Page.Title }} <sup>{{ .Count }}</sup></a>
          {{- end -}}
        {{- end -}}
      </div>
    {{- end -}}
  </div>
{{- end -}}
