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) --- layouts/partials/post/outdated-info-warning.html | 28 ++++++++++++++++++++++++ layouts/partials/scripts.html | 16 ++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 layouts/partials/post/outdated-info-warning.html (limited to 'layouts/partials') 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) -}}