hugo-theme-stack/layouts/partials/widget/taxonomy.html
Jacob Zhong 4be110e540
refactor(widget): taxonomy widget (#763)
* Add link to navbar sections and refactor names

* Prevent duplicate tags and categories information

* Add style to the widget links

* refactor: add `taxonomy` widget

Replaces `categories` and `tag-cloud` widget.

* style: remove unused `font_size_{{ .Count }}` in `taxonomy` widget

---------

Co-authored-by: Jimmy Cai <hi@jimmycai.com>
2023-08-27 18:26:53 +02:00

32 lines
1.3 KiB
HTML

{{- $query := first 1 (where (where .Context.Site.Pages "Kind" "taxonomy") "Type" .Params.type) -}}
{{- $context := .Context -}}
{{- $limit := default 10 .Params.limit -}}
{{- $hideInTaxonomyPage := default true .Params.hideInTaxonomyPage -}}
{{- if $query -}}
{{- $taxonomyPage := index $query 0 -}}
{{- $isTaxonomyPage := eq .Context $taxonomyPage -}}
{{- if not (and $isTaxonomyPage $hideInTaxonomyPage) -}}
<section class="widget tagCloud">
<div class="widget-icon">
{{- partial "helper/icon" (default "tag" .Params.icon) -}}
</div>
<h2 class="widget-title section-title">
<a class="widget-link" href="{{ $taxonomyPage.RelPermalink }}">
{{- default $taxonomyPage.Title .Params.title -}}
</a>
</h2>
<div class="tagCloud-tags">
{{- $pages := index $context.Site.Taxonomies .Params.type -}}
{{- $pagesSorted := $pages.ByCount -}}
{{- range first $limit $pagesSorted -}}
<a href="{{ .Page.RelPermalink }}">
{{- .Page.Title -}}
</a>
{{- end -}}
</div>
</section>
{{- end -}}
{{- else -}}
{{- warnf "Taxonomy [%s] not found." .Params.type -}}
{{- end -}}