From 1b9b9e4a9424bb9d1436312d3c49fc06ee35cb75 Mon Sep 17 00:00:00 2001 From: geekifan Date: Mon, 21 Apr 2025 10:32:50 +0800 Subject: [PATCH] add side panel --- i18n/en.yaml | 6 +++++- i18n/zh.yaml | 6 +++++- layouts/_default/baseof.html | 2 ++ layouts/partials/trending-tags.html | 32 +++++++++++++++++++++++++++++ layouts/partials/update-list.html | 29 ++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 layouts/partials/trending-tags.html create mode 100644 layouts/partials/update-list.html diff --git a/i18n/en.yaml b/i18n/en.yaml index 91423bc..479cf05 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -13,4 +13,8 @@ layout: search: hint: "Search" - cancel: "Cancel" \ No newline at end of file + cancel: "Cancel" + +panel: + lastmod: "Recently Updated" + trending_tags: "Trending Tags" diff --git a/i18n/zh.yaml b/i18n/zh.yaml index 6a156f7..b30f8fc 100644 --- a/i18n/zh.yaml +++ b/i18n/zh.yaml @@ -13,4 +13,8 @@ layout: search: hint: "搜索" - cancel: "取消" \ No newline at end of file + cancel: "取消" + +panel: + lastmod: "最近更新" + trending_tags: "热门标签" diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 7ac811c..670a39f 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -23,6 +23,8 @@ diff --git a/layouts/partials/trending-tags.html b/layouts/partials/trending-tags.html new file mode 100644 index 0000000..cae3fc3 --- /dev/null +++ b/layouts/partials/trending-tags.html @@ -0,0 +1,32 @@ + +{{ $MAX := 10 }} +{{ $allTags := slice }} + + +{{ range $name, $taxonomy := .Site.Taxonomies.tags }} + {{ $allTags = $allTags | append (dict "name" $name "count" $taxonomy.Count) }} +{{ end }} + + +{{ $sortedTags := sort $allTags "count" "desc" }} +{{ $sortedTags = sort $sortedTags "name" "asc" }} + + +{{ $trendingTags := slice }} +{{ range $i, $tag := $sortedTags }} + {{ if lt (len $trendingTags) $MAX }} + {{ $trendingTags = $trendingTags | append $tag.name }} + {{ end }} +{{ end }} + +{{ if gt (len $trendingTags) 0 }} +
+

{{ T "panel.trending_tags" }}

+
+ {{ range $trendingTags }} + {{ $url := printf "/tags/%s/" (urlize .) }} + + {{ end }} +
+
+{{ end }} \ No newline at end of file diff --git a/layouts/partials/update-list.html b/layouts/partials/update-list.html new file mode 100644 index 0000000..873a891 --- /dev/null +++ b/layouts/partials/update-list.html @@ -0,0 +1,29 @@ + +{{ $MAX_SIZE := 5 }} +{{ $all_posts := slice }} + +{{ range $index, $post := where site.RegularPages "Type" "in" site.Params.mainSections }} + {{ $datetime := $post.Lastmod | default $post.Date }} + {{ $elem := printf "%s::%d" ($datetime.Format "20060102150405") $index }} + {{ $all_posts = $all_posts | append $elem }} +{{ end }} + +{{ $all_posts = sort $all_posts "value" "desc" }} +{{ $update_list := first $MAX_SIZE $all_posts }} + +{{ if gt (len $update_list) 0 }} +
+

{{ T "panel.lastmod" }}

+ +
+ +{{ end }} \ No newline at end of file