From 2058c1ff6da9908aa2a90e485317ecf401833937 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 18 Feb 2026 18:56:15 +0100 Subject: [PATCH] refactor: create a generic `taxonomy` widget (#1268) * refactor: introduce a generic taxonomy widget and refactor existing category and tag cloud widgets to use it. * feat: Implement optional title linking for taxonomy widgets and enable parameter customization for taxonomy partials. * refactor: remove fallback to taxonomy page title for widget display Because this field always exists. I think it's better to let user customize via widget params * Update layouts/_partials/widget/taxonomy.html * refactor: check for .Params.taxonomy existence before accessing --- layouts/_partials/widget/categories.html | 18 ++--------- layouts/_partials/widget/tag-cloud.html | 18 ++--------- layouts/_partials/widget/taxonomy.html | 39 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 layouts/_partials/widget/taxonomy.html diff --git a/layouts/_partials/widget/categories.html b/layouts/_partials/widget/categories.html index 10c8a35..7179b77 100644 --- a/layouts/_partials/widget/categories.html +++ b/layouts/_partials/widget/categories.html @@ -1,16 +1,2 @@ -{{- $context := .Context -}} -{{- $limit := default 10 .Params.limit -}} -
-
- {{ partial "helper/icon" "categories" }} -
-

{{ T "widget.categoriesCloud.title" }}

- -
- {{ range first $limit $context.Site.Taxonomies.categories.ByCount }} - - {{ .Page.Title }} - - {{ end }} -
-
+{{ $params := merge (dict "taxonomy" "categories" "title" (T "widget.categoriesCloud.title") "icon" "categories") .Params }} +{{ partial "widget/taxonomy" (dict "Context" .Context "Params" $params) }} \ No newline at end of file diff --git a/layouts/_partials/widget/tag-cloud.html b/layouts/_partials/widget/tag-cloud.html index 37edf52..88c3e46 100644 --- a/layouts/_partials/widget/tag-cloud.html +++ b/layouts/_partials/widget/tag-cloud.html @@ -1,16 +1,2 @@ -{{- $context := .Context -}} -{{- $limit := default 10 .Params.limit -}} -
-
- {{ partial "helper/icon" "tag" }} -
-

{{ T "widget.tagCloud.title" }}

- -
- {{ range first $limit $context.Site.Taxonomies.tags.ByCount }} - - {{ .Page.Title }} - - {{ end }} -
-
+{{ $params := merge (dict "taxonomy" "tags" "title" (T "widget.tagCloud.title") "icon" "tag") .Params }} +{{ partial "widget/taxonomy" (dict "Context" .Context "Params" $params) }} \ No newline at end of file diff --git a/layouts/_partials/widget/taxonomy.html b/layouts/_partials/widget/taxonomy.html new file mode 100644 index 0000000..cdb3e5b --- /dev/null +++ b/layouts/_partials/widget/taxonomy.html @@ -0,0 +1,39 @@ +{{- $context := .Context -}} + +{{- if not .Params.taxonomy -}} + {{- warnf "Taxonomy field is required" -}} +{{- end -}} + +{{- $taxonomy := index $context.Site.Taxonomies .Params.taxonomy -}} +{{- if not $taxonomy -}} + {{- warnf "Taxonomy %s not found" .Params.taxonomy -}} +{{- end -}} + +{{- $taxonomyPage := $taxonomy.Page -}} +{{- $widgetTitle := .Params.title -}} +{{- $limit := default 10 .Params.limit -}} +{{- $icon := default .Params.taxonomy .Params.icon -}} +{{- $showLink := default false .Params.showLink -}} + +
+
+ {{ partial "helper/icon" $icon }} +
+

+ {{ if $showLink }} + + {{ $widgetTitle }} + + {{ else }} + {{ $widgetTitle }} + {{ end }} +

+ +
+ {{ range first $limit $taxonomy.ByCount }} + + {{ .Page.Title }} + + {{ end }} +
+