From f059fe9c9b7a5b5fad5f942efde8aecfd621c262 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Fri, 25 Feb 2022 14:17:28 +0800 Subject: [PATCH] :sparkles: Feat: add recently updated section (#50) --- CHANGELOG.md | 1 + assets/css/_partial/_archive/_terms.scss | 1 - exampleSite/config.toml | 7 +++++ .../theme-documentation-basics/index.en.md | 6 +++++ .../theme-documentation-basics/index.zh-cn.md | 6 +++++ i18n/en.toml | 6 ++++- i18n/zh-CN.toml | 6 ++++- i18n/zh-TW.toml | 6 ++++- layouts/_default/section.html | 3 ++- layouts/partials/recently-updated.html | 27 +++++++++++++++++++ ...Reminder.html => expiration-reminder.html} | 0 layouts/posts/rss.xml | 14 ++++++++++ layouts/posts/single.html | 2 +- 13 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 layouts/partials/recently-updated.html rename layouts/partials/single/{expirationReminder.html => expiration-reminder.html} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eed83e5..ec90ced2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - :tada: Feat: add Artalk comment support ([#54](https://github.com/Lruihao/FixIt/issues/54), [#57](https://github.com/Lruihao/FixIt/pull/57)@hiifong) - :tada: Feat: add Waline comment support ([#36](https://github.com/Lruihao/FixIt/issues/36)) - :tada: Feat: add Twikoo comment support ([#64](https://github.com/Lruihao/FixIt/issues/64)) +- :sparkles: Feat: add recently updated section ([#50](https://github.com/Lruihao/FixIt/issues/50)) - :sparkles: Style: add media style for print view ([#61](https://github.com/Lruihao/FixIt/issues/61)) - :sparkles: Feat: add pageStyle option ([#62](https://github.com/Lruihao/FixIt/issues/62)) - :sparkles: Feat: add article expiration reminder support ([#51](https://github.com/Lruihao/FixIt/issues/51)) diff --git a/assets/css/_partial/_archive/_terms.scss b/assets/css/_partial/_archive/_terms.scss index 6af5b53d..66da6b8d 100644 --- a/assets/css/_partial/_archive/_terms.scss +++ b/assets/css/_partial/_archive/_terms.scss @@ -68,7 +68,6 @@ } .archive-item-date { - width: 4em; text-align: right; color: $global-font-secondary-color; white-space: nowrap; diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 46b4946b..87332230 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -591,6 +591,13 @@ enableEmoji = true # amount of RSS pages # RSS 文章数目 rss = 10 + # recently updated posts settings since v0.2.13 + # 最近更新文章设置 since v0.2.13 + [params.section.recentlyUpdated] + enable = true + rss = true + days = 30 + maxCount = 10 # List (category or tag) page config # List (目录或标签) 页面配置 diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index 7af8a614..3671293d 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -298,6 +298,12 @@ Please open the code block below to view the complete sample configuration :(far dateFormat = "01-02" # amount of RSS pages rss = 10 + # {{< version 0.2.13 >}} recently updated posts settings + [params.section.recentlyUpdated] + enable = false + rss = false + days = 30 + maxCount = 10 # {{< version 0.2.0 >}} List (category or tag) page config [params.list] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md index 28b2c669..b2703f44 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -309,6 +309,12 @@ hugo dateFormat = "01-02" # RSS 文章数目 rss = 10 + # {{< version 0.2.13 >}} 最近更新文章设置 + [params.section.recentlyUpdated] + enable = false + rss = false + days = 30 + maxCount = 10 # {{< version 0.2.0 >}} List(目录或标签)页面配置 [params.list] diff --git a/i18n/en.toml b/i18n/en.toml index fd7a5612..210ff005 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -29,9 +29,13 @@ other = "Category" [categories] other = "Categories" - # === Taxonomy === +# === Section === +[recentlyUpdated] +other = "Recently Updated" +# === Section === + # === Pagination === [more] other = "More" diff --git a/i18n/zh-CN.toml b/i18n/zh-CN.toml index 2e49e991..468994d3 100644 --- a/i18n/zh-CN.toml +++ b/i18n/zh-CN.toml @@ -30,9 +30,13 @@ other = "分类" [categories] other = "分类" - # === Taxonomy === +# === Section === +[recentlyUpdated] +other = "最近更新" +# === Section === + # === Pagination === [more] other = "更多" diff --git a/i18n/zh-TW.toml b/i18n/zh-TW.toml index fbef6d9e..6d483d7d 100644 --- a/i18n/zh-TW.toml +++ b/i18n/zh-TW.toml @@ -30,9 +30,13 @@ other = "分類" [categories] other = "分類" - # === Taxonomy === +# === Section === +[recentlyUpdated] +other = "最近更新" +# === Section === + # === Pagination === [more] other = "更多" diff --git a/layouts/_default/section.html b/layouts/_default/section.html index f4fa31f2..35cfd2ab 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -17,6 +17,7 @@ {{- else -}} {{- $pages = .Paginate $pages -}} {{- end -}} + {{- partial "recently-updated.html" . -}} {{- range $pages.PageGroups -}}

{{ .Key }}

{{- range .Pages -}} @@ -24,7 +25,7 @@ {{- .Title -}} - + {{- $.Site.Params.section.dateFormat | default "01-02" | .Date.Format -}} diff --git a/layouts/partials/recently-updated.html b/layouts/partials/recently-updated.html new file mode 100644 index 00000000..e3d86ff7 --- /dev/null +++ b/layouts/partials/recently-updated.html @@ -0,0 +1,27 @@ +{{- if and .Site.Params.section.recentlyUpdated.enable (eq $.Paginator.PageNumber 1) -}} + {{- $hasTitle := false }} + {{- $postCount := 0 -}} + {{- $maxPostCount := .Site.Params.section.recentlyUpdated.maxCount | default 10 -}} + {{- $days := .Site.Params.section.recentlyUpdated.days | default 30 -}} + {{- range (where .Data.Pages.ByLastmod.Reverse "Section" "!=" "") -}} + {{- if gt (add .Lastmod.Unix (mul 86900 $days)) now.Unix -}} + {{- if lt $postCount $maxPostCount -}} + {{- if ne .Lastmod.Unix .Date.Unix }} + {{- $postCount = add $postCount 1 -}} + {{- if eq $hasTitle false -}} +

{{- T "recentlyUpdated" -}}

+ {{- $hasTitle = true -}} + {{- end -}} +
+ + {{- .Title -}} + + + {{- default $.Site.Params.section.dateFormat | default "01-02" | .Lastmod.Format -}} + +
+ {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/layouts/partials/single/expirationReminder.html b/layouts/partials/single/expiration-reminder.html similarity index 100% rename from layouts/partials/single/expirationReminder.html rename to layouts/partials/single/expiration-reminder.html diff --git a/layouts/posts/rss.xml b/layouts/posts/rss.xml index 884679a6..1c298ba4 100644 --- a/layouts/posts/rss.xml +++ b/layouts/posts/rss.xml @@ -34,6 +34,20 @@ {{- end -}} + {{- if .Site.Params.section.recentlyUpdated.rss -}} + {{- $postCount := 0 -}} + {{- $maxPostCount := .Site.Params.section.recentlyUpdated.maxCount | default 10 -}} + {{- $days := .Site.Params.section.recentlyUpdated.days | default 30 -}} + {{- range (where .Data.Pages.ByLastmod.Reverse "Section" "!=" "") -}} + {{- if gt (add .Lastmod.Unix (mul 86900 $days)) now.Unix -}} + {{- if lt $postCount $maxPostCount -}} + {{- if ne .Lastmod.Unix .Date.Unix }} + {{- dict "Page" . "Site" .Site | partial "rss/item.html" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} {{- range .Pages | first (.Site.Params.section.rss | default 10) -}} {{- dict "Page" . "Site" .Site | partial "rss/item.html" -}} {{- end -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index d5ed3218..a80e379c 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -123,7 +123,7 @@ {{- /* Content */ -}}
{{- /* Expiration Reminder */ -}} - {{- partial "single/expirationReminder.html" . -}} + {{- partial "single/expiration-reminder.html" . -}} {{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}