Skip to content

Commit

Permalink
✨ Feat: add article expiration reminder support (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Feb 22, 2022
1 parent 874b45f commit 1044abd
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
# 是否显示代码块的复制按钮
Expand Down
3 changes: 3 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down
3 changes: 3 additions & 0 deletions i18n/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ other = "主页"

[readMore]
other = "阅读全文"

[expirationReminder]
other = "本文最后更新于 {{ .Date }},文中内容可能已过时。"
# === posts/single.html ===

# === 404.html ===
Expand Down
3 changes: 3 additions & 0 deletions i18n/zh-TW.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ other = "主頁"

[readMore]
other = "閱讀全文"

[expirationReminder]
other = "本文最後更新於 {{ .Date }},文中內容可能已過時。"
# === posts/single.html ===

# === 404.html ===
Expand Down
34 changes: 34 additions & 0 deletions layouts/partials/single/expirationReminder.html
Original file line number Diff line number Diff line change
@@ -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 -}}
<div class="details admonition {{ $type }} open">
<div class="details-summary admonition-title">
<i class="icon fas {{ $icon }} fa-fw"></i>{{ T $type }}<i class="details-icon fas fa-angle-right fa-fw"></i>
</div>
<div class="details-content">
<div class="admonition-content">
{{- with .Site.Params.dateformat | default "2006-01-02" | $updateTime.Format -}}
{{- dict "Date" . | T "expirationReminder" -}}
{{- end -}}
</div>
</div>
</div>
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ <h2 class="single-subtitle">{{ . }}</h2>

{{- /* Content */ -}}
<div class="content" id="content">
{{- /* Expiration Reminder */ -}}
{{- partial "single/expirationReminder.html" . -}}
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
</div>

Expand Down

0 comments on commit 1044abd

Please sign in to comment.