diff --git a/layouts/partials/hb/modules/blog/functions/filter-taxonomies.html b/layouts/partials/hb/modules/blog/functions/filter-taxonomies.html new file mode 100644 index 00000000..8061aa13 --- /dev/null +++ b/layouts/partials/hb/modules/blog/functions/filter-taxonomies.html @@ -0,0 +1,31 @@ +{{- $opts := . }} +{{- $defaultLimit := default 10 $opts.limit }} +{{- $defaultCount := default true $opts.count }} +{{- $taxonomies := slice }} +{{- range $name, $taxonomy := site.Taxonomies }} + {{- $limit := $defaultLimit }} + {{- $count := $defaultCount }} + {{- $weight := 10 }} + {{- with index $opts $name }} + {{- if default false .disable }} + {{- continue }} + {{- end }} + {{- with .limit }} + {{- $limit = . }} + {{- end }} + {{- if isset . "count" }} + {{- $count = .count }} + {{- end }} + {{- with .weight }} + {{- $weight = . }} + {{- end }} + {{- end }} + {{- $taxonomies = $taxonomies | append (dict + "name" $name + "terms" (first $limit $taxonomy.ByCount) + "count" $count + "weight" $weight) + }} +{{- end }} +{{- return sort $taxonomies "weight" }} + diff --git a/layouts/partials/hb/modules/blog/taxonomies/default.html b/layouts/partials/hb/modules/blog/taxonomies/default.html index 411e65de..fb4fcc65 100644 --- a/layouts/partials/hb/modules/blog/taxonomies/default.html +++ b/layouts/partials/hb/modules/blog/taxonomies/default.html @@ -1,26 +1,22 @@ -{{- $limit := default 10 .limit }} -{{- $count := default true .count }} -{{- range $name, $taxonomy := site.Taxonomies }} - {{- $idx := 0 }} +{{- $taxonomies := partial "hb/modules/blog/functions/filter-taxonomies" . }} +{{- range $taxonomies }} + {{- $name := .name }} + {{- $count := .count }}
{{- with site.GetPage $name }}
{{- .Title -}}
{{- end }} - {{- range $termName, $term := $taxonomy.ByCount }} - {{- if eq $idx $limit }} - {{- break }} - {{- end }} + {{- range .terms }} - {{- $term.Page.Title -}} + href="{{ .Page.RelPermalink }}"> + {{- .Page.Title -}} {{- if $count }} - {{- printf " (%d)" $term.Count -}} + {{- printf " (%d)" .Count -}} {{- end }} - {{- $idx = add $idx 1 }} {{- end }}
{{- end }} diff --git a/layouts/partials/hb/modules/blog/taxonomies/toggle.html b/layouts/partials/hb/modules/blog/taxonomies/toggle.html index 0853ac13..42ec38a2 100644 --- a/layouts/partials/hb/modules/blog/taxonomies/toggle.html +++ b/layouts/partials/hb/modules/blog/taxonomies/toggle.html @@ -1,13 +1,13 @@ {{- $style := default "pills" .style }} -{{- $limit := default 10 .limit }} -{{- $count := default true .count }} +{{- $taxonomies := partial "hb/modules/blog/functions/filter-taxonomies" . }}