add generator.js

dev
ehlxr 2016-11-18 11:02:45 +08:00
parent 7847e2471e
commit 3f8126e7de
2 changed files with 29 additions and 1 deletions

28
resources/generator.js Normal file
View File

@ -0,0 +1,28 @@
'use strict';
var pagination = require('hexo-pagination');
module.exports = function(locals){
var config = this.config;
var posts = locals.posts;
posts.data = posts.data.sort(function(a, b) {
if(a.top && b.top) { // 两篇文章top都有定义
if(a.top == b.top) return b.date - a.date; // 若top值一样则按照文章日期降序排
else return b.top - a.top; // 否则按照top值降序排
}
else if(a.top && !b.top) { // 以下是只有一篇文章top有定义那么将有top的排在前面这里用异或操作居然不行233
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
}
});
};

@ -1 +1 @@
Subproject commit 2601e01098aa2ee6f859abfb40e3886581959dc9
Subproject commit 8767da787d2a927e8e84304cfb757d7e0a1428ef