hexo-theme-fluid icon indicating copy to clipboard operation
hexo-theme-fluid copied to clipboard

能否给时间久远的文章增加友好的提示

Open jumbalab opened this issue 6 years ago • 1 comments

image 超过30天文章增加文章提示

具体实现我是在这篇文章 https://www.txisfine.cn/archives/d7ece4ad.html 看到的

jumbalab avatar Sep 28 '20 02:09 jumbalab

可以通过 Hexo5 的注入器实现:

hexo.extend.injector.register('body_end', `
<script type="text/javascript">
(function() {
  var times = document.getElementsByTagName('time');
  if (times.length === 0) { return; }
  var posts = document.getElementsByClassName('post-content');
  if (posts.length === 0) { return; }

  var pubTime = new Date(times[0].dateTime);  /* 文章发布时间戳 */
  var now = Date.now()  /* 当前时间戳 */
  var interval = parseInt(now - pubTime)
  /* 发布时间超过指定时间(毫秒) */
  if (interval > 3600*24*30*1000){
    var days = parseInt(interval / 86400000)
    posts[0].innerHTML = '<div class="note note-warning" style="font-size:0.9rem"><p>' +
      '<div class="h6">文章时效性提示</div><p>这是一篇发布于 ' + days + ' 天前的文章,部分信息可能已发生改变,请注意甄别。' +
      '</p></p></div>' + posts[0].innerHTML;
  }
})();
</script>
`);

具体用法可参见 这篇文章

zkqiang avatar Dec 11 '20 16:12 zkqiang