diff --git a/archetypes/default.md b/archetypes/default.md index 1049a50ba..f4ff84001 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 98ac4fb86..3c11c581c 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 742082765..48870d693 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 d1d826fa4..ea6e079c0 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 061c149bc..9262efe0f 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 2d064f01f..b6ecf5c28 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 000000000..3736c1341 --- /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 b0879824c..8b2ae9443 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) -}}