主页文章按更新时间排序
针对目前最新的hexo版本
hexo: 6.3.0
NexT version 8.18.1
结合感谢名单中作则的文章,终于,我在node_modules\hexo-generator-index\lib\generator.js文件中找到了似乎是用于排序的代码,
该文件是为了添加文章置顶功能的,但当置顶等级设置相同时,按照发布日期进行排序。
对JavaScript改完之后该文件中的内容如下所示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| 'use strict';
const pagination = require('hexo-pagination');
module.exports = function(locals) { const config = this.config; const posts = locals.posts.sort(config.index_generator.order_by);
posts.data = posts.data.sort(function (a, b) { if (a.sticky && b.sticky) { if (a.sticky == b.sticky) return b.updated - a.updated; else return b.sticky - a.sticky; } else if (a.sticky && !b.sticky) { return -1; } else if (!a.sticky && b.sticky) { return 1; } else return b.updated - a.updated; });
const paginationDir = config.pagination_dir || 'page'; const path = config.index_generator.path || '';
return pagination(path, posts, { perPage: config.index_generator.per_page, layout: ['index', 'archive'], format: paginationDir + '/%d/', data: { __index: true } }); };
|
详细的hexo版本信息:
hexo: 6.3.0
hexo-cli: 4.3.1
os: darwin 21.2.0 12.1
node: 16.13.0
v8: 9.4.146.19-node.13
uv: 1.42.0
zlib: 1.2.11
brotli: 1.0.9
ares: 1.17.2
modules: 93
nghttp2: 1.45.1
napi: 8
llhttp: 6.0.4
openssl: 1.1.1l+quic
cldr: 39.0
icu: 69.1
tz: 2021a
unicode: 13.0
ngtcp2: 0.1.0-DEV
nghttp3: 0.1.0-DEV
感谢思路来源
hexo笔记:文章排序
个性化需求沟通 扫客服加V加群: