-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
能添加置顶文章功能吗 #12
Comments
just add |
Test Results
|
Refer: 解决Hexo置顶问题
'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) { // 若top值一样
if(config.index_generator.order_by == 'updated') {
// 按照文章修改日期降序排
return b.updated - a.updated;
}
else {
// 按照文章日期降序排
return b.date - a.date;
}
}
else return b.top - a.top; // 否则按照top值降序排
}
else if(a.top && !b.top) { // 以下是只有一篇文章top有定义,那么将有top的排在前面
return -1;
}
else if(!a.top && b.top) {
return 1;
}
else { // 都没定义top值
if(config.index_generator.order_by == 'updated') {
// 按照文章修改日期降序排
return b.updated - a.updated;
}
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
}
});
};
index_generator:
path: ''
per_page: 10 ##首頁默認8篇文章標題 如果值爲0不分頁
# order_by: updated
order_by: date |
Hexo 已实现文章置顶参数: hexojs/hexo-generator-index#51 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
**相关章节链接: **
希望能够把某些文章置顶让所有人第一时间看到,要如何做呢
The text was updated successfully, but these errors were encountered: