Skip to content

Commit

Permalink
config+layout: Add category list in home sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
lixk28 committed Dec 1, 2024
1 parent 92222ec commit 77d5938
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions layouts/partials/sidebar/category-list.html
Original file line number Diff line number Diff line change
@@ -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 }}
<span><a href="{{ .page.Permalink }}">[{{ .page.Title }}]</a></span>
{{- $.args.delimiter | default "&emsp;" | safeHTML -}}
{{ end }}

0 comments on commit 77d5938

Please sign in to comment.