Skip to content

Conversation

@firstmetcs
Copy link

总览

该修改涉及以下方面:

  • 添加了“文章时效性”提示

功能点

“文章时效性”提示

效果

image

配置

post:
  # 在文章开头显示文章过期/时效提示
  outdate: 
    enable: false
    # 文章时效提示使用警告样式的天数,超过此天数显示警告样式的note
    warning_day: 200
    # 文章时效提示使用错误样式的天数,超过此天数显示错误样式的note
    error_day: 400

功能点详述

功能使用post.outdate配置“文章时效性”提示,开启后若文章发布日期位于warning_dayerror_day之间,则显示警告note样式,若大于error_day则显示错误样式,文案如:这是一篇发布于1000天前的文章,部分信息可能已发生改变,请注意甄别。

修复点

修复了 #1051

@ghost
Copy link

ghost commented Dec 15, 2024

感觉有点进退两难,这样写没有算上可能的更新时间,
如果增加算上更新时间又可能会出现 #1025 所提到的情况。
(所以最好果然还是手动在front-matter中定义更新时间吧)

我这样改了改:

            <!-- 文章时效性提示 -->
            <%
              // 判断是否有 page.updated
              // 如果有,则使用 page.updated 时间;否则使用 page.date 时间作为文章的发布时间
              let useUpdated = !!page.updated; // 将 page.updated 转换成布尔值
              let articleDate = useUpdated ? new Date(page.updated) : new Date(page.date); // 根据是否有 page.updated 来选择文章发布时间
              let interval = parseInt(Date.now() - articleDate);
            %>
            <% 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><%- __('post.outdate.title') %></h5>

                  <% if (useUpdated) { %>
                    <p><%- __('post.outdate.content_updated', parseInt(interval / 86400000)) %></p>
                  <% } else { %>
                    <p><%- __('post.outdate.content', parseInt(interval / 86400000)) %></p>
                  <% } %>
                </div>
              <% } else if (interval > theme.post.outdate.error_day * 3600 * 24 * 1000) { %>
                <div class="note note-danger">
                  <h5><%- __('post.outdate.title') %></h5>

                  <% if (useUpdated) { %>
                    <p><%- __('post.outdate.content_updated', parseInt(interval / 86400000)) %></p>
                  <% } else { %>
                    <p><%- __('post.outdate.content', parseInt(interval / 86400000)) %></p>
                  <% } %>
                </div>
              <% } %>
            <% } %>

不知道改过后搭配手动定义文章更新时间怎么样,😂
最影响的还是文件本身的属性信息。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants