Skip to content

Commit 3a419af

Browse files
committed
添加“文章时效性”提示
1 parent 2ebdb34 commit 3a419af

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

_config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ post:
578578
# Options: busuanzi | leancloud
579579
source: "busuanzi"
580580

581+
# 在文章开头显示文章过期/时效提示
582+
# Display expiration/expiration notification at the beginning of the article
583+
outdate:
584+
enable: false
585+
# 文章时效提示使用警告样式的天数,超过此天数显示警告样式的note
586+
# The number of days for the article's timeliness prompt to use warning style, exceeding this number of days will display warning style notes
587+
warning_day: 200
588+
# 文章时效提示使用错误样式的天数,超过此天数显示错误样式的note
589+
# The number of days for the article's timeliness prompt to use the wrong style. If this number is exceeded, a note with the wrong style will be displayed
590+
error_day: 400
591+
581592
# 在文章开头显示文章更新时间,该时间默认是 md 文件更新时间,可通过 front-matter 中 `updated` 手动指定(和 date 一样格式)
582593
# Update date is displayed at the beginning of the post. The default date is the update date of the md file, which can be manually specified by `updated` in front-matter (same format as date)
583594
updated:

layout/post.ejs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
1515
<div id="board">
1616
<article class="post-content mx-auto">
1717
<h1 id="seo-header"><%= page.subtitle || page.title %></h1>
18+
<% let interval = parseInt(Date.now() - new Date(page.date)) %>
19+
<% if (theme.post.outdate.enable) { %>
20+
<% if (interval > theme.post.outdate.warning_day * 3600 * 24 * 1000 && interval < theme.post.outdate.error_day * 3600 * 24 * 1000) { %>
21+
<div class="note note-warning">
22+
<h5>文章时效性提示</h5>
23+
<p>这是一篇发布于 <%- parseInt(interval / 86400000) %> 天前的文章,部分信息可能已发生改变,请注意甄别。</p>
24+
</div>
25+
<% } else if(interval > theme.post.outdate.error_day * 3600 * 24 * 1000) { %>
26+
<div class="note note-danger">
27+
<h5>文章时效性提示</h5>
28+
<p>这是一篇发布于 <%- parseInt(interval / 86400000) %> 天前的文章,部分信息可能已发生改变,请注意甄别。</p>
29+
</div>
30+
<% } %>
31+
<% } %>
1832
<% if (theme.post.updated.enable && theme.post.updated && compare_date(page.date, page.updated)) { %>
1933
<p id="updated-time" class="note note-<%= theme.post.updated.note_class || 'info' %>" style="<%= theme.post.updated.relative ? 'display: none' : '' %>">
2034
<% if (theme.post.updated.relative) { %>

0 commit comments

Comments
 (0)