借助**别人的代码**添加了添加了置顶功能, 写在这里以备忘:
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 34 35
| 'use strict'; var pagination = require('hexo-pagination'); module.exports = function (locals) { var config = this.config; var posts = locals.posts;
posts.data.forEach(function (post, idx) { if (post.top) { post.title = '[置顶]' + post.title; } });
posts.data = posts.data.sort(function (a, b) { if (a.top && b.top) { if (a.top == b.top) return b.date - a.date; else return b.top - a.top; } else if (a.top && !b.top) { return -1; } else if (!a.top && b.top) { return 1; } else return b.date - a.date; }); var paginationDir = config.pagination_dir || 'page'; return pagination('', posts, { perPage: config.index_generator.per_page, layout: ['index', 'archive'], format: paginationDir + '/%d/', data: { __index: true } }); };
|
替换hexo-generate-index
插件中的 lib/generate.js