Skip to content

Commit

Permalink
feat(sidebar/taxonomies): allow sorting, disabling, limiting each tax…
Browse files Browse the repository at this point in the history
…onomy (#559)
  • Loading branch information
razonyang committed Dec 17, 2023
1 parent 9822a85 commit 8ae81d4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
30 changes: 30 additions & 0 deletions layouts/partials/hb/modules/blog/functions/filter-taxonomies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- $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" }}
20 changes: 8 additions & 12 deletions layouts/partials/hb/modules/blog/taxonomies/default.html
Original file line number Diff line number Diff line change
@@ -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 }}
<div class="taxonomy-terms hb-module">
{{- with site.GetPage $name }}
<div class="taxonomy-terms-title h5">
<a class="text-decoration-none" href="{{ .RelPermalink }}">{{- .Title -}}</a>
</div>
{{- end }}
{{- range $termName, $term := $taxonomy.ByCount }}
{{- if eq $idx $limit }}
{{- break }}
{{- end }}
{{- range .terms }}
<a
class="taxonomy-term taxonomy-term-{{ $name }} btn btn-sm btn-outline-secondary my-1 me-1"
href="{{ $term.Page.RelPermalink }}">
{{- $term.Page.Title -}}
href="{{ .Page.RelPermalink }}">
{{- .Page.Title -}}
{{- if $count }}
{{- printf " (%d)" $term.Count -}}
{{- printf " (%d)" .Count -}}
{{- end }}
</a>
{{- $idx = add $idx 1 }}
{{- end }}
</div>
{{- end }}
29 changes: 13 additions & 16 deletions layouts/partials/hb/modules/blog/taxonomies/toggle.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{- $style := default "pills" .style }}
{{- $limit := default 10 .limit }}
{{- $count := default true .count }}
{{- $taxonomies := partial "hb/modules/blog/functions/filter-taxonomies" . }}
<ul class="nav nav-{{ $style }} nav-justified mb-2" role="tablist">
{{- $first := true }}
{{- range $name, $taxonomy := site.Taxonomies }}
{{- if not $taxonomy }}
{{- range $taxonomies }}
{{- $name := .name }}
{{- if not .terms }}
{{- continue }}
{{- end }}
{{- $page := site.GetPage $name }}
{{- $page := site.GetPage .name }}
<li class="nav-item" role="presentation">
<button
class="nav-link{{ cond $first ` active` `` }}"
Expand All @@ -26,8 +26,10 @@
</ul>
<div class="tab-content">
{{- $first := true }}
{{- range $name, $taxonomy := site.Taxonomies }}
{{- if not $taxonomy }}
{{- range $taxonomies }}
{{- $name := .name }}
{{- $count := .count }}
{{- if not .terms }}
{{- continue }}
{{- end }}
<div
Expand All @@ -36,20 +38,15 @@
role="tabpanel"
aria-labelledby="taxonomy-{{ $name }}-tab"
tabindex="0">
{{- $idx := 0 }}
{{- range $termName, $term := $taxonomy.ByCount }}
{{- if eq $idx $limit }}
{{- break }}
{{- end }}
{{- range $termName, $term := .terms }}
<a
class="taxonomy-term taxonomy-term-{{ $name }} btn btn-sm btn-outline-secondary p-1 me-1 mb-1"
href="{{ $term.Page.RelPermalink }}">
{{- $term.Page.Title -}}
href="{{ .Page.RelPermalink }}">
{{- .Page.Title -}}
{{- if $count }}
{{- printf " (%d)" $term.Count -}}
{{- printf " (%d)" .Count -}}
{{- end }}
</a>
{{- $idx = add $idx 1 }}
{{- end }}
</div>
{{- $first = false }}
Expand Down

0 comments on commit 8ae81d4

Please sign in to comment.