From 77d5938f1d93b86b777bcc67db2942104323051a Mon Sep 17 00:00:00 2001 From: Xuekun Li Date: Mon, 2 Dec 2024 00:42:42 +0800 Subject: [PATCH] config+layout: Add category list in home sidebar --- config.toml | 10 ++++++++++ exampleSite/config.toml | 10 ++++++++++ layouts/partials/sidebar/category-list.html | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 layouts/partials/sidebar/category-list.html diff --git a/config.toml b/config.toml index 9a7c06a..e9c8188 100644 --- a/config.toml +++ b/config.toml @@ -75,6 +75,16 @@ # Sort by {count | random}, default is count sortBy = "count" + [[params.home.sidebar.items]] + id = "category-list" + title = "Categories" + weight = 4 + [params.home.sidebar.items.args] + size = 5 + delimiter = " " + # Sort by {count | random}, default is count + sortBy = "count" + [params.codeblock] maxLinesOfCode = 64 diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 852f3d8..5d265a3 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -78,6 +78,16 @@ themesDir = "../.." # Sort by {count | random}, default is count sortBy = "count" + [[params.home.sidebar.items]] + id = "category-list" + title = "Categories" + weight = 4 + [params.home.sidebar.items.args] + size = 5 + delimiter = " " + # Sort by {count | random}, default is count + sortBy = "count" + [params.codeblock] maxLinesOfCode = 64 diff --git a/layouts/partials/sidebar/category-list.html b/layouts/partials/sidebar/category-list.html new file mode 100644 index 0000000..3fede24 --- /dev/null +++ b/layouts/partials/sidebar/category-list.html @@ -0,0 +1,18 @@ +{{ $tags := slice }} +{{ range .page.Site.Taxonomies.categories }} + {{ $tags = $tags | append (dict + "page" .Page + "count" .Count + ) }} +{{ end }} + +{{ if eq .args.sortBy "count" }} + {{ $tags = sort $tags "count" "desc" }} +{{ else if eq .args.sortBy "random" }} + {{ $tags = $tags | shuffle }} +{{ end }} + +{{ range $tags }} + [{{ .page.Title }}] + {{- $.args.delimiter | default " " | safeHTML -}} +{{ end }}