diff --git a/CHANGELOG.md b/CHANGELOG.md index 144ddb86..d5958764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - :tada: Feat: add Twikoo comment support ([#64](https://github.com/Lruihao/FixIt/issues/64)) - :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)) - :sparkles: Feat: add 9 newly supported social links ([#17](https://github.com/Lruihao/FixIt/issues/17)) - :sparkles: Feat: update cell-watermark 1.0.3 and support CDN (fontFamily supported) - :sparkles: Feat: add Gravatar mirror site support ([#66](https://github.com/Lruihao/FixIt/pull/66)@ctj12461) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index b73c8ea1..96fe2afe 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -656,6 +656,19 @@ enableEmoji = true # position of TOC ("left", "right") since v0.2.13 # 目录位置 ("left", "right") since v0.2.13 position = "right" + # Display a message at the beginning of an article to warn the reader that its content might be expired. since v0.2.13 + # 在文章开头显示提示信息,提醒读者文章内容可能过时。 since v0.2.13 + [params.page.expirationReminder] + enable = true + # Display the reminder if the last modified time is more than 90 days ago + # 如果文章最后更新于这天数之前,显示提醒 + reminder = 90 + # Display warning if the last modified time is more than 180 days ago + # 如果文章最后更新于这天数之前,显示警告 + warning = 180 + # If the article expires, close the comment or not + # 如果文章到期是否关闭评论 + closeComment = false # Code config # 代码配置 [params.page.code] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index c1b723fe..bbcf887c 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -448,6 +448,15 @@ Please open the code block below to view the complete sample configuration :(far auto = true # {{< version 0.2.13 >}} position of TOC ("left", "right") position = "right" + # {{< version 0.2.13 >}} Display a message at the beginning of an article to warn the reader that its content might be expired + [params.page.expirationReminder] + enable = false + # Display the reminder if the last modified time is more than 90 days ago + reminder = 90 + # Display warning if the last modified time is more than 180 days ago + warning = 180 + # If the article expires, close the comment or not + closeComment = false # {{< version 0.2.0 changed >}} {{< link "https://katex.org/" KaTeX >}} mathematical formulas (https://katex.org) [params.page.math] enable = true 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 bf995280..36f35cbc 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -459,6 +459,15 @@ hugo auto = true # {{< version 0.2.13 >}} 目录位置 ("left", "right") position = "right" + # {{< version 0.2.13 >}} 在文章开头显示提示信息,提醒读者文章内容可能过时 + [params.page.expirationReminder] + enable = false + # 如果文章最后更新于这天数之前,显示提醒 + reminder = 90 + # 如果文章最后更新于这天数之前,显示警告 + warning = 180 + # 如果文章到期是否关闭评论 + closeComment = false # {{< version 0.2.0 >}} 代码配置 [params.page.code] # 是否显示代码块的复制按钮 diff --git a/i18n/en.toml b/i18n/en.toml index 2d4b80e1..fcf966a0 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -145,6 +145,9 @@ other = "Home" [readMore] other = "Read More" + +[expirationReminder] +other = "This article was last updated on {{ .Date }}, the content may be out of date." # === posts/single.html === # === 404.html === diff --git a/i18n/zh-CN.toml b/i18n/zh-CN.toml index b0c8aa0e..1ed55cd1 100644 --- a/i18n/zh-CN.toml +++ b/i18n/zh-CN.toml @@ -150,6 +150,9 @@ other = "主页" [readMore] other = "阅读全文" + +[expirationReminder] +other = "本文最后更新于 {{ .Date }},文中内容可能已过时。" # === posts/single.html === # === 404.html === diff --git a/i18n/zh-TW.toml b/i18n/zh-TW.toml index cf977995..77686ae1 100644 --- a/i18n/zh-TW.toml +++ b/i18n/zh-TW.toml @@ -150,6 +150,9 @@ other = "主頁" [readMore] other = "閱讀全文" + +[expirationReminder] +other = "本文最後更新於 {{ .Date }},文中內容可能已過時。" # === posts/single.html === # === 404.html === diff --git a/layouts/partials/single/expirationReminder.html b/layouts/partials/single/expirationReminder.html new file mode 100644 index 00000000..39f9c50f --- /dev/null +++ b/layouts/partials/single/expirationReminder.html @@ -0,0 +1,34 @@ +{{- $params := .Scratch.Get "params" -}} +{{- $expirationReminder := $params.expirationReminder | default dict -}} + +{{- if $expirationReminder.enable -}} + {{- $daysAgo := div (sub now.Unix .Lastmod.Unix) 86400 }} + {{- $reminderThreshold := $expirationReminder.reminder | default 90 }} + {{- $warningThreshold := $expirationReminder.warning | default 180 }} + {{- $updateTime := .Lastmod }} + + {{- if gt $daysAgo $reminderThreshold -}} + {{- $type := "note" -}} + {{- $icon := "fa-pencil-alt" -}} + {{- if gt $daysAgo $warningThreshold -}} + {{- $type = "warning" -}} + {{- $icon = "fa-exclamation-triangle" -}} + {{- /* If the article expires, close the comment or not */ -}} + {{- if $expirationReminder.closeComment -}} + {{- .Scratch.Set "comment" dict -}} + {{- end -}} + {{- end -}} +