Comments (5)
@zkqiang 我知道可以通过类似hexo.extend.injector.register('body_end', '<script src="/js/outdate.js"></script>','post')
和script添加,但是看到其他有些主题有这个功能,所以想添加一下。确实存在update time不可靠的情况,所以pr只通过time做简单的判断,也是提供一个思路吧。
PS: 很棒的主题~
对于后续需要此功能的同学提供个简单的实现方式,使用注入器(Injector) | Hexo
在 Hexo 的 scripts 目录(没有则新建一个)下新建一个名为 injector.js 的文件,将下面的代码复制到其中:
//注入文章过期提示
hexo.extend.injector.register('body_end', `<script src="/js/outdate.js"></script>`,'post')
在 Hexo 的 source 目录下新建 js 文件夹,新建一个名为 outdate.js 的文件,添加以下代码:
window.onload = function() {
//不同的日期显示不同的样式,200 天为黄色提示,400天为红色提示,可以自己定义。
let warningDay = 200;
let errorDay = 400;
// 确保能够获取到文章时间以及在文章详情页
let times = document.getElementsByTagName('time');
if (times.length === 0) { return; }
let posts = document.getElementsByClassName('post-content');
if (posts.length === 0) { return; }
// 获取系统当前的时间
let pubTime = new Date(times[0].dateTime); /* 文章发布时间戳 */
let now = Date.now() /* 当前时间戳 */
let interval = parseInt(now - pubTime)
let days = parseInt(interval / 86400000)
/* 发布时间超过指定时间(毫秒) */
//note warning 以及 note danger 是 Next 主题的自定义模板语法,如果使用其他主题,请自行更改样式以达到最佳显示效果
if (interval > warningDay*3600*24*1000 && interval < errorDay*3600*24*1000){
posts[0].innerHTML = '<div class="note note-warning">' +
'<h5>文章时效性提示</h5><p>这是一篇发布于 ' + days + ' 天前的文章,部分信息可能已发生改变,请注意甄别。</p>' +
'</div>' + posts[0].innerHTML;
}else if(interval >= errorDay*3600*24*1000){
posts[0].innerHTML = '<div class="note note-danger">' +
'<h5>文章时效性提示</h5><p>这是一篇发布于 ' + days + ' 天前的文章,部分信息可能已发生改变,请注意甄别。</p>' +
'</div>' + posts[0].innerHTML;
}
};
from hexo-theme-fluid.
https://butterfly.js.org/posts/4aa8abbe/#%E6%96%87%E7%AB%A0%E9%81%8E%E6%9C%9F%E6%8F%90%E9%86%92
from hexo-theme-fluid.
from hexo-theme-fluid.
为什么不想加这个功能,是因为加了后还要考虑 update time 的情况(不考虑的话不出多长时间大概率会有个 issue 来提这个问题),而 update time 在静态生成里并不一定可靠(类似于#1025),所以一直没加这个功能,而是放在文章里让大家自定义。
当然还是感谢你的 PR,我会再考虑下这个问题。
from hexo-theme-fluid.
如上面的同学提及的butterfly以及搜集资料时看到的keep 主题都已经添加的对应的功能
from hexo-theme-fluid.
Related Issues (20)
- 将首页头图高度设置为0时(`banner_img_height: 0`),顶栏和文章列表异常
- 永远加载不完的进度条 HOT 2
- 关于valine评论系统 HOT 1
- 侧边栏无法显示同标签文章 HOT 1
- 自定义页面使用已有的布局
- VSCode插件-方便自動貼上snippet(Hexo Snippet Paste Tool for Fluid v1.0.0釋出) HOT 1
- 在开启代理的情况下前端页面无法正常加载 HOT 2
- 如何使勾选框的 text 部分支持 markdown
- Giscus 评论区背景加载失败 HOT 3
- banner_img设置不生效,我在_config.fluid.yml设置的banner_img不被加载,看前端加载的还是default.png
- 删除/替换淘宝镜像相关依赖包 HOT 2
- 文章在首页的缩略图可不可以在全局配置啊? HOT 1
- 分类页面的banner_img是怎么配置的? HOT 1
- 怎么使用gitee的评论系统啊? HOT 2
- 关于文章页面点击目录后,点击后推键不会退出这个页面而是会跳回上一个目录
- 关于点击目录后回退问题
- 折疊塊內部的行內程式碼區塊不會跳脫
- 如何设置评论插件的 path?
- Bug:代码块高光修改后只在localhost生效,对远程部署的网页不生效 HOT 1
- tag_map被忽略
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hexo-theme-fluid.