From c974c905e52449c4e5e1b1149ecafd57b2519732 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Fri, 11 Oct 2024 11:15:55 +0800 Subject: [PATCH] :sparkles: Feat: add recently updated pages support for archives, section and term list and remove recentlyUpdated.rss --- hugo.toml | 15 ++++++------ layouts/_default/home.archives.html | 3 ++- layouts/partials/feed/rss.html | 1 - layouts/partials/init/index.html | 2 +- layouts/partials/recently-updated.html | 34 ++++++++++++++++++++------ layouts/taxonomy/list.html | 1 + 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/hugo.toml b/hugo.toml index 0e75ab6b4..e4a14d690 100644 --- a/hugo.toml +++ b/hugo.toml @@ -507,13 +507,6 @@ enableEmoji = true limit = -1 # whether to show the full text content in feed. fullText = false - # FixIt 0.2.13 | NEW recently updated pages config - # TODO refactor to support archives, section, taxonomy and term - [params.section.recentlyUpdated] - enable = false - rss = false - days = 30 - maxCount = 10 # Term list (category or tag) page config [params.list] @@ -528,6 +521,14 @@ enableEmoji = true # whether to show the full text content in feed. fullText = false + # FixIt 0.3.13 | NEW recently updated pages config for archives, section and term list + [params.recentlyUpdated] + archives = true + section = true + list = true + days = 30 + maxCount = 10 + # FixIt 0.2.17 | NEW TagCloud config for tags page [params.tagcloud] enable = false diff --git a/layouts/_default/home.archives.html b/layouts/_default/home.archives.html index 2ed469051..0ae4d2664 100644 --- a/layouts/_default/home.archives.html +++ b/layouts/_default/home.archives.html @@ -39,6 +39,7 @@

{{- else -}} {{- $pages = .Paginate $pages -}} {{- end -}} + {{- partial "recently-updated.html" . -}} {{- range $pages.PageGroups -}}

{{- dict "Class" "fa-regular fa-calendar fa-fw me-1" | partial "plugin/icon.html" -}} @@ -52,7 +53,7 @@

{{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}} {{- end -}} {{- /* Use the original title after archiving the articles */ -}} - {{- cond (.Param "capitalizeTitles") (title .Title) (.Title) -}} + {{- cond (.Param "capitalizeTitles") (title .Title) .Title -}} {{- .Date | dateFormat ($.Site.Params.archives.dateFormat | default "01-02") -}} diff --git a/layouts/partials/feed/rss.html b/layouts/partials/feed/rss.html index 969924bda..b6ba8f89b 100644 --- a/layouts/partials/feed/rss.html +++ b/layouts/partials/feed/rss.html @@ -6,7 +6,6 @@ {{- if ge .Config.limit 1 -}} {{- $pages = $pages | first .Config.limit -}} {{- end -}} -{{- $length := $pages.Len -}} {{- printf "" | safeHTML }} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 9ea48b94f..c0adc6ce2 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.13-b32f1a99" -}} +{{- .Scratch.Set "version" "v0.3.13-da4664b6" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/partials/recently-updated.html b/layouts/partials/recently-updated.html index f08c8ab67..77ec40231 100644 --- a/layouts/partials/recently-updated.html +++ b/layouts/partials/recently-updated.html @@ -1,11 +1,25 @@ -{{- /* Recently updated pages */ -}} -{{- /* TODO refactor to support archives, section, taxonomy and term. */ -}} -{{- if and .Site.Params.section.recentlyUpdated.enable (eq $.Paginator.PageNumber 1) -}} +{{- /* Recently updated pages for archives, section and term list */ -}} +{{- $kindMap := dict + "home" "archives" + "section" "section" + "term" "list" +-}} +{{- $recentlyUpdatedConfig := .Site.Params.recentlyUpdated -}} +{{- $scope := index $kindMap .Kind -}} +{{- $scopeEnable := index $recentlyUpdatedConfig $scope | default false -}} +{{- if $scopeEnable | and (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 first $maxPostCount (where .Data.Pages.ByLastmod.Reverse "Section" "!=" "") -}} + {{- $maxPostCount := $recentlyUpdatedConfig.maxCount | default 10 -}} + {{- $days := $recentlyUpdatedConfig.days | default 30 -}} + {{- $dateformat := (index .Site.Params $scope).dateformat | default "01-02" -}} + {{- $scopePages := .Pages -}} + {{- if eq $scope "archives" -}} + {{- $scopePages = .Scratch.Get "mainSectionPages" -}} + {{- end -}} + {{- $scopePages = where $scopePages.ByLastmod.Reverse "Section" "!=" "" -}} + {{- /* {{- $scopePages = where $scopePages "File.IsContentAdapter" "ne" true -}} */ -}} + {{- range first $maxPostCount $scopePages -}} {{- if gt (add .Lastmod.Unix (mul 86900 $days)) now.Unix -}} {{- if ne .Lastmod.Unix .Date.Unix }} {{- $postCount = add $postCount 1 -}} @@ -22,10 +36,14 @@

{{- if eq $repost.enable true -}} {{- dict "Class" "fa-solid fa-share fa-fw text-success me-1" | partial "plugin/icon.html" -}} {{- end -}} - {{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}} + {{- if eq $scope "archives" -}} + {{- cond (.Param "capitalizeTitles") (title .Title) .Title -}} + {{- else -}} + {{- cond (.Param "capitalizeTitles") (title .LinkTitle) .LinkTitle -}} + {{- end -}} - {{- with .Lastmod | dateFormat (.Site.Params.section.dateformat | default "01-02") -}} + {{- with .Lastmod | dateFormat $dateformat -}} {{- dict "Date" . | T "single.updatedOnDate" -}} {{- end -}} diff --git a/layouts/taxonomy/list.html b/layouts/taxonomy/list.html index ce5e3d7ce..ab5992703 100644 --- a/layouts/taxonomy/list.html +++ b/layouts/taxonomy/list.html @@ -34,6 +34,7 @@

{{- else -}} {{- $pages = .Paginate $pages -}} {{- end -}} + {{- partial "recently-updated.html" . -}} {{- range $pages.PageGroups -}}

{{- dict "Class" "fa-regular fa-calendar fa-fw me-1" | partial "plugin/icon.html" -}}