Hexo Keep主题修改首页文章展示时间 version< 4.1.0
小轲 Lv3

Note

新的时间查阅官网文档后,主题更新版本到 4.1.0 就可以支持这个特性啦,不需要再修改源码。如果你的版本低于4.1.0,那么下面的文章可以帮到你。

https://keep-docs.xpoet.cn/basis/configuration-guide/home.html#post-datetime

原因

在批量更新hexo的markdown文章文件后,发现首页的时间是以更新文章为准。

image

个人喜好,此处的文章想展示为createTime ,看了一遍Keep的文档,发现没得到什么解决方案,看起来只能去改源码了

在修改源码之前,其实还有一些注意事项:

  1. 不建议直接修改源代码,可能会在更新模板版本时遇见的问题
    1. 如使用NPM更新,则修改后的文件会被新的NPM版本直接覆盖
    2. 如使用Git更新,则可能会出现pull失败,因为代码冲突或者版本的原因

权衡利弊+强迫症考虑后,还是决定改一下

修改源码

找到 /themes/keep/layout/_partial/home-article-meta-info.ejs 文件,修改头部的三目运算符变量规则即可。

1
2
3
4
<%
//const target_date = post.date !== post.updated ? post.updated : post.date
const target_date = post.date !== post.updated ? post.date : post.updated
%>
 评论