From 4be110e540fb7840c051f18d3e6f47d7d5f0bad7 Mon Sep 17 00:00:00 2001 From: Jacob Zhong Date: Sun, 27 Aug 2023 12:26:53 -0400 Subject: [PATCH] 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 --- assets/scss/partials/widgets.scss | 8 +++++++ exampleSite/config/_default/params.toml | 8 +++++-- i18n/ar.yaml | 6 ----- i18n/bn.yaml | 4 ---- i18n/ca.yaml | 4 ---- i18n/de.yaml | 4 ---- i18n/el.yaml | 2 -- i18n/en.yaml | 4 ---- i18n/es.yaml | 4 ---- i18n/fa.yaml | 4 ---- i18n/fr.yaml | 2 -- i18n/hu.yaml | 4 ---- i18n/id.yaml | 4 ---- i18n/it.yaml | 4 ---- i18n/ja.yaml | 4 ---- i18n/ko.yaml | 6 ----- i18n/nl.yaml | 4 ---- i18n/pl.yaml | 5 ---- i18n/pt-br.yaml | 6 ----- i18n/pt-pt.yaml | 6 ----- i18n/ru.yaml | 2 -- i18n/th.yaml | 2 -- i18n/tr.yaml | 2 -- i18n/uk.yaml | 2 -- i18n/vi.yaml | 8 ------- i18n/zh-cn.yaml | 4 ---- i18n/zh-hk.yaml | 4 ---- i18n/zh-tw.yaml | 4 ---- layouts/_default/list.html | 2 +- layouts/partials/widget/archives.html | 4 +++- layouts/partials/widget/categories.html | 16 ------------- layouts/partials/widget/tag-cloud.html | 16 ------------- layouts/partials/widget/taxonomy.html | 32 +++++++++++++++++++++++++ 33 files changed, 50 insertions(+), 141 deletions(-) delete mode 100644 layouts/partials/widget/categories.html delete mode 100644 layouts/partials/widget/tag-cloud.html create mode 100644 layouts/partials/widget/taxonomy.html diff --git a/assets/scss/partials/widgets.scss b/assets/scss/partials/widgets.scss index 42cfcc2..b1b7b3e 100644 --- a/assets/scss/partials/widgets.scss +++ b/assets/scss/partials/widgets.scss @@ -65,3 +65,11 @@ } } } + +/* Color for widget titles */ +.widget-title a.widget-link { + color: var(--accent-color); + &:hover { + color: var(--accent-color-darker); + } +} diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index a87c986..ef3afa0 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -74,16 +74,20 @@ type = "archives" limit = 5 [[widgets.homepage]] -type = "categories" +type = "taxonomy" [widgets.homepage.params] limit = 10 +type = "tags" +icon = "tag" [[widgets.homepage]] -type = "tag-cloud" +type = "taxonomy" [widgets.homepage.params] limit = 10 +type = "categories" +icon = "categories" [[widgets.page]] type = "toc" diff --git a/i18n/ar.yaml b/i18n/ar.yaml index 61e0262..6e391e5 100644 --- a/i18n/ar.yaml +++ b/i18n/ar.yaml @@ -29,12 +29,6 @@ widget: title: الارشيفات more: اكثر - tagCloud: - title: وسوم - - categoriesCloud: - title: التصنيفات - search: title: بحث placeholder: اكتب... diff --git a/i18n/bn.yaml b/i18n/bn.yaml index 0e3e511..ede587e 100644 --- a/i18n/bn.yaml +++ b/i18n/bn.yaml @@ -35,10 +35,6 @@ widget: archives: title: আর্কাইভ more: আরও - tagCloud: - title: ট্যাগ - categoriesCloud: - title: বিভাগ search: title: অনুসন্ধান diff --git a/i18n/ca.yaml b/i18n/ca.yaml index da2428b..7812049 100644 --- a/i18n/ca.yaml +++ b/i18n/ca.yaml @@ -28,10 +28,6 @@ widget: archives: title: Arxiu more: Més - tagCloud: - title: Etiquetes - categoriesCloud: - title: Categories search: title: Cerca diff --git a/i18n/de.yaml b/i18n/de.yaml index ff0e351..f7b4c73 100644 --- a/i18n/de.yaml +++ b/i18n/de.yaml @@ -28,10 +28,6 @@ widget: archives: title: Archiv more: Weitere - tagCloud: - title: Schlagwörter - categoriesCloud: - title: Kategorien search: title: Suche diff --git a/i18n/el.yaml b/i18n/el.yaml index 486914a..3f478bc 100644 --- a/i18n/el.yaml +++ b/i18n/el.yaml @@ -28,8 +28,6 @@ widget: archives: title: Αρχειο more: Περισσότερα - tagCloud: - title: Tags search: title: Αναζήτηση diff --git a/i18n/en.yaml b/i18n/en.yaml index 3f94ab1..38ba63c 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -31,10 +31,6 @@ widget: archives: title: Archives more: More - tagCloud: - title: Tags - categoriesCloud: - title: Categories search: title: Search diff --git a/i18n/es.yaml b/i18n/es.yaml index 5614e98..13f2c77 100644 --- a/i18n/es.yaml +++ b/i18n/es.yaml @@ -28,10 +28,6 @@ widget: archives: title: Archivo more: Más - tagCloud: - title: Etiquetas - categoriesCloud: - title: Categorías search: title: Búsqueda diff --git a/i18n/fa.yaml b/i18n/fa.yaml index 9de30b5..bcefbe3 100644 --- a/i18n/fa.yaml +++ b/i18n/fa.yaml @@ -28,10 +28,6 @@ widget: archives: title: آرشیو more: بیشتر - tagCloud: - title: تگ ها - categoriesCloud: - title: دسته بندی search: title: جستجو diff --git a/i18n/fr.yaml b/i18n/fr.yaml index f18805c..ddc6224 100644 --- a/i18n/fr.yaml +++ b/i18n/fr.yaml @@ -28,8 +28,6 @@ widget: archives: title: Archives more: Autres - tagCloud: - title: Mots clés search: title: Rechercher diff --git a/i18n/hu.yaml b/i18n/hu.yaml index 0e8c6e5..8baf956 100644 --- a/i18n/hu.yaml +++ b/i18n/hu.yaml @@ -28,10 +28,6 @@ widget: archives: title: Archívum more: Több - tagCloud: - title: Cimkék - categoriesCloud: - title: Kategóriák search: title: Keresés diff --git a/i18n/id.yaml b/i18n/id.yaml index 42e9461..1f10ee1 100644 --- a/i18n/id.yaml +++ b/i18n/id.yaml @@ -28,10 +28,6 @@ widget: archives: title: Arsip more: Lebih - tagCloud: - title: Tag - categoriesCloud: - title: Kategori search: title: Cari diff --git a/i18n/it.yaml b/i18n/it.yaml index 81f3fb4..9c4a0aa 100644 --- a/i18n/it.yaml +++ b/i18n/it.yaml @@ -28,10 +28,6 @@ widget: archives: title: Archivi more: Di più - tagCloud: - title: Tags - categoriesCloud: - title: Categorie search: title: Cerca diff --git a/i18n/ja.yaml b/i18n/ja.yaml index 4a1c85f..83c0885 100644 --- a/i18n/ja.yaml +++ b/i18n/ja.yaml @@ -17,10 +17,6 @@ widget: archives: title: アーカイブ more: さらに見る - tagCloud: - title: タグ - categoriesCloud: - title: カテゴリ search: title: 検索 diff --git a/i18n/ko.yaml b/i18n/ko.yaml index 05c0530..da8a88f 100644 --- a/i18n/ko.yaml +++ b/i18n/ko.yaml @@ -28,12 +28,6 @@ widget: archives: title: 보관함 more: 더보기 - - categoriesCloud: - title: 카테고리 - - tagCloud: - title: 태그 search: title: 검색 diff --git a/i18n/nl.yaml b/i18n/nl.yaml index 620d915..ce8b498 100644 --- a/i18n/nl.yaml +++ b/i18n/nl.yaml @@ -23,10 +23,6 @@ widget: archives: title: Archief more: Meer - tagCloud: - title: Tags - categoriesCloud: - title: Categorie search: title: Zoeken diff --git a/i18n/pl.yaml b/i18n/pl.yaml index fc27ccd..ce508b7 100644 --- a/i18n/pl.yaml +++ b/i18n/pl.yaml @@ -34,11 +34,6 @@ widget: archives: title: Archiwum more: Więcej - tagCloud: - title: Tagi - - categoriesCloud: - title: Kategorie search: title: Szukaj diff --git a/i18n/pt-br.yaml b/i18n/pt-br.yaml index b1235cb..df63aae 100644 --- a/i18n/pt-br.yaml +++ b/i18n/pt-br.yaml @@ -29,12 +29,6 @@ widget: title: Arquivos more: Mais - tagCloud: - title: Tags - - categoriesCloud: - title: Categorias - search: title: Busca placeholder: Digite algo... diff --git a/i18n/pt-pt.yaml b/i18n/pt-pt.yaml index f524969..2b24075 100644 --- a/i18n/pt-pt.yaml +++ b/i18n/pt-pt.yaml @@ -45,12 +45,6 @@ widget: other: Arquivos more: other: Mais - tagCloud: - title: - other: Tags - categoriesCloud: - title: - other: Categorias search: title: diff --git a/i18n/ru.yaml b/i18n/ru.yaml index d04e8a3..8238d4d 100644 --- a/i18n/ru.yaml +++ b/i18n/ru.yaml @@ -30,8 +30,6 @@ widget: archives: title: Архивы more: Ещё - tagCloud: - title: Теги search: title: Поиск diff --git a/i18n/th.yaml b/i18n/th.yaml index 81e54d3..e64ab2e 100644 --- a/i18n/th.yaml +++ b/i18n/th.yaml @@ -28,8 +28,6 @@ widget: archives: title: เนื้อหาที่เก็บถาวรแล้ว more: อื่นๆ นอกจากนี้ - tagCloud: - title: แท็ก search: title: ค้นหา diff --git a/i18n/tr.yaml b/i18n/tr.yaml index 0df564a..2d4d157 100644 --- a/i18n/tr.yaml +++ b/i18n/tr.yaml @@ -23,8 +23,6 @@ widget: archives: title: Arşiv more: Daha fazla - tagCloud: - title: Etiketler search: title: Arama diff --git a/i18n/uk.yaml b/i18n/uk.yaml index 2e29e26..21163b5 100644 --- a/i18n/uk.yaml +++ b/i18n/uk.yaml @@ -29,8 +29,6 @@ widget: archives: title: Архіви more: Більше - tagCloud: - title: Теґи search: title: Пошук diff --git a/i18n/vi.yaml b/i18n/vi.yaml index 13dc624..b1605b9 100644 --- a/i18n/vi.yaml +++ b/i18n/vi.yaml @@ -48,14 +48,6 @@ widget: more: other: Còn nữa - tagCloud: - title: - other: Nhãn dán - - categoriesCloud: - title: - other: Chuỗi bài - search: title: other: Tìm kiếm diff --git a/i18n/zh-cn.yaml b/i18n/zh-cn.yaml index e744d08..12a7ac6 100644 --- a/i18n/zh-cn.yaml +++ b/i18n/zh-cn.yaml @@ -17,10 +17,6 @@ widget: archives: title: 归档 more: 更多 - tagCloud: - title: 标签云 - categoriesCloud: - title: 分类 search: title: 搜索 diff --git a/i18n/zh-hk.yaml b/i18n/zh-hk.yaml index 4f701ba..97f7476 100644 --- a/i18n/zh-hk.yaml +++ b/i18n/zh-hk.yaml @@ -28,10 +28,6 @@ widget: archives: title: Archives more: 更多 - tagCloud: - title: Tags - categoriesCloud: - title: Categories search: title: 搜尋 diff --git a/i18n/zh-tw.yaml b/i18n/zh-tw.yaml index 00fa403..674734f 100644 --- a/i18n/zh-tw.yaml +++ b/i18n/zh-tw.yaml @@ -29,10 +29,6 @@ widget: archives: title: 紀錄 more: 更多 - tagCloud: - title: 標籤雲 - categoriesCloud: - title: 分類 search: title: 搜尋 diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 4e1e0b5..a8a2620 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -11,7 +11,7 @@

{{ T "list.page" (len .Pages) }}

-

{{ .Title }}

+

{{ default (strings.FirstUpper .Type) .Title }}

{{ with .Params.description }}

{{ . }}

{{ end }} diff --git a/layouts/partials/widget/archives.html b/layouts/partials/widget/archives.html index e42da27..106c57d 100644 --- a/layouts/partials/widget/archives.html +++ b/layouts/partials/widget/archives.html @@ -7,7 +7,9 @@
{{ partial "helper/icon" "infinity" }}
-

{{ T "widget.archives.title" }}

+

+ {{ T "widget.archives.title" }} +

{{ $pages := where $context.Site.RegularPages "Type" "in" $context.Site.Params.mainSections }} {{ $archives := $pages.GroupByDate "2006" }} diff --git a/layouts/partials/widget/categories.html b/layouts/partials/widget/categories.html deleted file mode 100644 index 10c8a35..0000000 --- a/layouts/partials/widget/categories.html +++ /dev/null @@ -1,16 +0,0 @@ -{{- $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 }} -
-
diff --git a/layouts/partials/widget/tag-cloud.html b/layouts/partials/widget/tag-cloud.html deleted file mode 100644 index e64e5e2..0000000 --- a/layouts/partials/widget/tag-cloud.html +++ /dev/null @@ -1,16 +0,0 @@ -{{- $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 }} -
-
\ 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..baf5171 --- /dev/null +++ b/layouts/partials/widget/taxonomy.html @@ -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) -}} +
+
+ {{- partial "helper/icon" (default "tag" .Params.icon) -}} +
+

+ + {{- default $taxonomyPage.Title .Params.title -}} + +

+ +
+ {{- $pages := index $context.Site.Taxonomies .Params.type -}} + {{- $pagesSorted := $pages.ByCount -}} + {{- range first $limit $pagesSorted -}} + + {{- .Page.Title -}} + + {{- end -}} +
+
+ {{- end -}} +{{- else -}} + {{- warnf "Taxonomy [%s] not found." .Params.type -}} +{{- end -}} \ No newline at end of file