Skip to content

Commit

Permalink
添加“文章时效性”提示
Browse files Browse the repository at this point in the history
  • Loading branch information
fancunshuo committed Jan 15, 2024
1 parent 2ebdb34 commit 3a419af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,17 @@ post:
# Options: busuanzi | leancloud
source: "busuanzi"

# 在文章开头显示文章过期/时效提示
# Display expiration/expiration notification at the beginning of the article
outdate:
enable: false
# 文章时效提示使用警告样式的天数,超过此天数显示警告样式的note
# The number of days for the article's timeliness prompt to use warning style, exceeding this number of days will display warning style notes
warning_day: 200
# 文章时效提示使用错误样式的天数,超过此天数显示错误样式的note
# 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
error_day: 400

# 在文章开头显示文章更新时间,该时间默认是 md 文件更新时间,可通过 front-matter 中 `updated` 手动指定(和 date 一样格式)
# 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)
updated:
Expand Down
14 changes: 14 additions & 0 deletions layout/post.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
<div id="board">
<article class="post-content mx-auto">
<h1 id="seo-header"><%= page.subtitle || page.title %></h1>
<% let interval = parseInt(Date.now() - new Date(page.date)) %>
<% if (theme.post.outdate.enable) { %>
<% if (interval > theme.post.outdate.warning_day * 3600 * 24 * 1000 && interval < theme.post.outdate.error_day * 3600 * 24 * 1000) { %>
<div class="note note-warning">
<h5>文章时效性提示</h5>
<p>这是一篇发布于 <%- parseInt(interval / 86400000) %> 天前的文章,部分信息可能已发生改变,请注意甄别。</p>
</div>
<% } else if(interval > theme.post.outdate.error_day * 3600 * 24 * 1000) { %>
<div class="note note-danger">
<h5>文章时效性提示</h5>
<p>这是一篇发布于 <%- parseInt(interval / 86400000) %> 天前的文章,部分信息可能已发生改变,请注意甄别。</p>
</div>
<% } %>
<% } %>
<% if (theme.post.updated.enable && theme.post.updated && compare_date(page.date, page.updated)) { %>
<p id="updated-time" class="note note-<%= theme.post.updated.note_class || 'info' %>" style="<%= theme.post.updated.relative ? 'display: none' : '' %>">
<% if (theme.post.updated.relative) { %>
Expand Down

0 comments on commit 3a419af

Please sign in to comment.