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>
This commit is contained in:
Jacob Zhong
2023-08-27 18:26:53 +02:00
committed by GitHub
co-authored by Jimmy Cai
parent 5063e8f0b8
commit 4be110e540
33 changed files with 50 additions and 141 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<div class="section-card">
<div class="section-details">
<h3 class="section-count">{{ T "list.page" (len .Pages) }}</h3>
<h1 class="section-term">{{ .Title }}</h1>
<h1 class="section-term">{{ default (strings.FirstUpper .Type) .Title }}</h1>
{{ with .Params.description }}
<h2 class="section-description">{{ . }}</h2>
{{ end }}
+3 -1
View File
@@ -7,7 +7,9 @@
<div class="widget-icon">
{{ partial "helper/icon" "infinity" }}
</div>
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
<h2 class="widget-title section-title">
<a class="widget-link" href="{{ $archivesPage.RelPermalink }}">{{ T "widget.archives.title" }}</a>
</h2>
{{ $pages := where $context.Site.RegularPages "Type" "in" $context.Site.Params.mainSections }}
{{ $archives := $pages.GroupByDate "2006" }}
-16
View File
@@ -1,16 +0,0 @@
{{- $context := .Context -}}
{{- $limit := default 10 .Params.limit -}}
<section class="widget tagCloud">
<div class="widget-icon">
{{ partial "helper/icon" "categories" }}
</div>
<h2 class="widget-title section-title">{{ T "widget.categoriesCloud.title" }}</h2>
<div class="tagCloud-tags">
{{ range first $limit $context.Site.Taxonomies.categories.ByCount }}
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
{{ .Page.Title }}
</a>
{{ end }}
</div>
</section>
-16
View File
@@ -1,16 +0,0 @@
{{- $context := .Context -}}
{{- $limit := default 10 .Params.limit -}}
<section class="widget tagCloud">
<div class="widget-icon">
{{ partial "helper/icon" "tag" }}
</div>
<h2 class="widget-title section-title">{{ T "widget.tagCloud.title" }}</h2>
<div class="tagCloud-tags">
{{ range first $limit $context.Site.Taxonomies.tags.ByCount }}
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
{{ .Page.Title }}
</a>
{{ end }}
</div>
</section>
+32
View File
@@ -0,0 +1,32 @@
{{- $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 -}}