Skip to content

Commit

Permalink
✨ Feat: add recently updated pages support for archives, section and …
Browse files Browse the repository at this point in the history
…term list

and remove recentlyUpdated.rss
  • Loading branch information
Lruihao committed Oct 11, 2024
1 parent 3edabbe commit c974c90
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
15 changes: 8 additions & 7 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion layouts/_default/home.archives.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h1 class="single-title animate__animated animate__pulse animate__faster">
{{- else -}}
{{- $pages = .Paginate $pages -}}
{{- end -}}
{{- partial "recently-updated.html" . -}}
{{- range $pages.PageGroups -}}
<h2 class="group-title">
{{- dict "Class" "fa-regular fa-calendar fa-fw me-1" | partial "plugin/icon.html" -}}
Expand All @@ -52,7 +53,7 @@ <h2 class="group-title">
{{- 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 -}}
</a>
<span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Date.Format }}'>
{{- .Date | dateFormat ($.Site.Params.archives.dateFormat | default "01-02") -}}
Expand Down
1 change: 0 additions & 1 deletion layouts/partials/feed/rss.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{{- if ge .Config.limit 1 -}}
{{- $pages = $pages | first .Config.limit -}}
{{- end -}}
{{- $length := $pages.Len -}}

{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -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" . -}}
Expand Down
34 changes: 26 additions & 8 deletions layouts/partials/recently-updated.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand All @@ -22,10 +36,14 @@ <h2 class="group-title">
{{- 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 -}}
</a>
<span class="archive-item-date" title='{{ "2006-01-02 15:04:05" | .Lastmod.Format }}'>
{{- with .Lastmod | dateFormat (.Site.Params.section.dateformat | default "01-02") -}}
{{- with .Lastmod | dateFormat $dateformat -}}
{{- dict "Date" . | T "single.updatedOnDate" -}}
{{- end -}}
</span>
Expand Down
1 change: 1 addition & 0 deletions layouts/taxonomy/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h1 class="single-title animate__animated animate__pulse animate__faster">
{{- else -}}
{{- $pages = .Paginate $pages -}}
{{- end -}}
{{- partial "recently-updated.html" . -}}
{{- range $pages.PageGroups -}}
<h2 class="group-title">
{{- dict "Class" "fa-regular fa-calendar fa-fw me-1" | partial "plugin/icon.html" -}}
Expand Down

0 comments on commit c974c90

Please sign in to comment.