From 9033266c2f02e570658a9505c26b7a438030f664 Mon Sep 17 00:00:00 2001 From: Keith Mo Date: Fri, 1 Jun 2018 00:06:14 +0800 Subject: feat(post): add out-of-date content warning (#68) --- archetypes/default.md | 4 ++++ exampleSite/config.toml | 9 ++++++++ i18n/en.yaml | 10 +++++++-- i18n/es.yaml | 6 +++++ i18n/fr.yaml | 6 +++++ i18n/zh-CN.yaml | 10 +++++++-- layouts/partials/post/outdated-info-warning.html | 28 ++++++++++++++++++++++++ layouts/partials/scripts.html | 16 ++++++++++++++ layouts/post/single.html | 3 +++ src/css/_partial/_post.scss | 5 +++-- src/css/_partial/_post/_outdated.scss | 25 +++++++++++++++++++++ static/lib/timeago/timeago-3.0.2.min.js | 1 + static/lib/timeago/timeago.locales-3.0.2.min.js | 1 + 13 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 layouts/partials/post/outdated-info-warning.html create mode 100644 src/css/_partial/_post/_outdated.scss create mode 100644 static/lib/timeago/timeago-3.0.2.min.js create mode 100644 static/lib/timeago/timeago.locales-3.0.2.min.js diff --git a/archetypes/default.md b/archetypes/default.md index 1049a50..f4ff840 100644 --- a/archetypes/default.md +++ b/archetypes/default.md @@ -26,6 +26,10 @@ mathjaxEnableAutoNumber: false # You unlisted posts you might want not want the header or footer to show hideHeaderAndFooter: false +# You can enable or disable out-of-date content warning for individual post. +# Comment this out to use the global config. +#enableOutdatedInfoWarning: false + flowchartDiagrams: enable: false options: "" diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 98ac4fb..3c11c58 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -98,6 +98,15 @@ copyright = "" # default: author.name ↓ # 默认为下面配 gitmentCSS = '' gitalkJS = '' gitalkCSS = '' + timeagoJS = '' + timeagoLocalesJS = '' + + # Display a message at the beginning of an article to warn the readers that it's content may be outdated. + # 在文章开头显示提示信息,提醒读者文章内容可能过时。 + [params.outdatedInfoWarning] + enable = false + hint = 30 # Display hint if the last modified time is more than these days ago. # 如果文章最后更新于这天数之前,显示提醒 + warn = 180 # Display warning if the last modified time is more than these days ago. # 如果文章最后更新于这天数之前,显示警告 [params.gitment] # Gitment is a comment system based on GitHub issues. see https://github.com/imsun/gitment owner = "" # Your GitHub ID diff --git a/i18n/en.yaml b/i18n/en.yaml index 7420827..48870d6 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -33,10 +33,10 @@ nextPage: prevPost: other: "Prev" - + nextPost: other: "Next" - + toc: other: "Contents" @@ -60,6 +60,12 @@ readingTime: one: "{{ .Count }} min read" other: "{{ .Count }} mins read" +outdatedInfoWarningBefore: + other: "[NOTE] Updated " + +outdatedInfoWarningAfter: + other: ". This article may have outdated content or subject matter." + # ===== content license ===== author: other: "Author" diff --git a/i18n/es.yaml b/i18n/es.yaml index d1d826f..ea6e079 100644 --- a/i18n/es.yaml +++ b/i18n/es.yaml @@ -60,6 +60,12 @@ readingTime: one: "{{ .Count }} min lectura" other: "{{ .Count }} mins lectura" +outdatedInfoWarningBefore: + other: "[NOTE] Updated " + +outdatedInfoWarningAfter: + other: ". This article may have outdated content or subject matter." + # ===== content license ===== author: other: "Autor" diff --git a/i18n/fr.yaml b/i18n/fr.yaml index 061c149..9262efe 100644 --- a/i18n/fr.yaml +++ b/i18n/fr.yaml @@ -60,6 +60,12 @@ readingTime: one: "{{ .Count }} min de lecture" other: "{{ .Count }} mins de lecture" +outdatedInfoWarningBefore: + other: "[NOTE] Updated " + +outdatedInfoWarningAfter: + other: ". This article may have outdated content or subject matter." + # ===== content license ===== author: other: "Auteur" diff --git a/i18n/zh-CN.yaml b/i18n/zh-CN.yaml index 2d064f0..b6ecf5c 100644 --- a/i18n/zh-CN.yaml +++ b/i18n/zh-CN.yaml @@ -33,10 +33,10 @@ nextPage: prevPost: other: "上一篇" - + nextPost: other: "下一篇" - + toc: other: "文章目录" @@ -60,6 +60,12 @@ readingTime: one: "预计阅读 {{ .Count }} 分钟" other: "预计阅读 {{ .Count }} 分钟" +outdatedInfoWarningBefore: + other: "【注意】最后更新于 " + +outdatedInfoWarningAfter: + other: ",文中内容可能已过时,请谨慎使用。" + # ===== content license ===== author: other: "文章作者" diff --git a/layouts/partials/post/outdated-info-warning.html b/layouts/partials/post/outdated-info-warning.html new file mode 100644 index 0000000..3736c13 --- /dev/null +++ b/layouts/partials/post/outdated-info-warning.html @@ -0,0 +1,28 @@ +{{- if or .Params.enableOutdatedInfoWarning (and .Site.Params.outdatedInfoWarning.enable (ne .Params.enableOutdatedInfoWarning false)) }} + {{- $daysAgo := div (sub now.Unix .Lastmod.Unix) 86400 }} + {{- $hintThreshold := .Site.Params.outdatedInfoWarning.hint | default 30 }} + {{- $warnThreshold := .Site.Params.outdatedInfoWarning.warn | default 180 }} + + {{- $updateTime := .Lastmod }} + {{- if .GitInfo }} + {{- if lt .GitInfo.AuthorDate.Unix .Lastmod.Unix }} + {{- $updateTime := .GitInfo.AuthorDate }} + {{- end }} + {{- end -}} + + {{- if gt $daysAgo $hintThreshold }} +
+ {{- if gt $daysAgo $warnThreshold }} +
+ {{- else }} +
+ {{- end }} +

{{ T "outdatedInfoWarningBefore" -}} + + {{- dateFormat "January 2, 2006" $updateTime -}} + {{ T "outdatedInfoWarningAfter" -}} +

+
+
+ {{- end -}} +{{- end -}} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index b087982..8b2ae94 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -10,6 +10,22 @@ {{ if .Site.Params.fancybox }}{{ end }} {{- end -}} + +{{- if and (or .Params.enableOutdatedInfoWarning (and .Site.Params.outdatedInfoWarning.enable (ne .Params.enableOutdatedInfoWarning false))) (or .IsPage .IsHome) }} + {{- if .Site.Params.publicCDN.enable }} + {{ .Site.Params.publicCDN.timeagoJS | safeHTML }} + {{ .Site.Params.publicCDN.timeagoLocalesJS | safeHTML }} + {{- else }} + + + {{- end }} + +{{- end }} + {{- if and (or .Params.flowchartDiagrams.enable (and .Site.Params.flowchartDiagrams.enable (ne .Params.flowchartDiagrams.enable false))) (or .IsPage .IsHome) -}}