diff options
author | Keith Mo <keith.mork@gmail.com> | 2018-06-01 00:06:14 +0800 |
---|---|---|
committer | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2018-06-01 00:06:14 +0800 |
commit | 9033266c2f02e570658a9505c26b7a438030f664 (patch) | |
tree | 3b5dabd3e1d911e2b1541294ab67b89a09166f7b /layouts/partials | |
parent | e1781a29e6ab9e484899b3dad07db2ace261ff93 (diff) |
feat(post): add out-of-date content warning (#68)
Diffstat (limited to 'layouts/partials')
-rw-r--r-- | layouts/partials/post/outdated-info-warning.html | 28 | ||||
-rw-r--r-- | layouts/partials/scripts.html | 16 |
2 files changed, 44 insertions, 0 deletions
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 }} + <div class="post-outdated"> + {{- if gt $daysAgo $warnThreshold }} + <div class="warn"> + {{- else }} + <div class="hint"> + {{- end }} + <p>{{ T "outdatedInfoWarningBefore" -}} + <span class="timeago" datetime="{{ dateFormat "2006-01-02T15:04:05" $updateTime }}" title="{{ dateFormat "January 2, 2006" $updateTime }}"> + {{- dateFormat "January 2, 2006" $updateTime -}} + </span>{{ T "outdatedInfoWarningAfter" -}} + </p> + </div> + </div> + {{- 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 }}<script type="text/javascript" src="{{ "lib/fancybox/jquery.fancybox-3.1.20.min.js" | relURL }}"></script>{{ end }} {{- end -}} +<!-- timeago.JS --> +{{- 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 }} + <script type="text/javascript" src="{{ "lib/timeago/timeago-3.0.2.min.js" | relURL }}"></script> + <script type="text/javascript" src="{{ "lib/timeago/timeago.locales-3.0.2.min.js" | relURL }}"></script> + {{- end }} +<script> // NOTE: timeago.js uses the language code format like "zh_CN" (underscore and case sensitive) + var languageCode = {{ .Site.LanguageCode }}.replace(/-/g, '_').replace(/_(.*)/, function ($0, $1) {return $0.replace($1, $1.toUpperCase());}); + timeago().render(document.querySelectorAll('.timeago'), languageCode); + timeago.cancel(); // stop update +</script> +{{- end }} + <!-- flowchart --> {{- if and (or .Params.flowchartDiagrams.enable (and .Site.Params.flowchartDiagrams.enable (ne .Params.flowchartDiagrams.enable false))) (or .IsPage .IsHome) -}} <script> |