hexo 补充时效性提醒

如图所示

实现方法

hexo 自动更新文章修改时间
\source\js 文件夹下(根目录中或主题中均可)创建 timecount.js 文件,其中输入下方代码

var now = new Date().getTime() // 当前时间戳
var postinfo = document.getElementsByClassName("post-date")[0]
//var postinfo__date_created = new Date(postinfo.innerText.split(" ")[1])//根据发布时间
var postinfo__date_created = new Date(postinfo.children[1].innerText.split(" ")[1])//根据更新时间
postinfo__date_created = postinfo__date_created.getTime() // 文章发布时间戳
//console.log("文章创建时间",postinfo__date_created)

var datepassing = parseInt(now - postinfo__date_created)
//console.log("过期时间",datepassing)
// 超过31天提示:3600*24*31*1000
if(datepassing > 2678400000){
    var out = parseInt(datepassing / 86400000)
    document.write("<div class=\"note info\"><p><strong>文章时效性提示</strong><br>这是一篇创建于 " + out + " 天前的文章,其中的信息可能已经有所发展或是发生改变。</p></div>")
}

在要开启提醒的文档中嵌入下列代码即可

<div>
    <script type="text/javascript" src="js/timecount.js"></script>
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值