hexo-theme-keep/scripts/helpers/helper.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

hexo.extend.helper.register('isInHomePaging', function (pagePath, route) {
2020-10-27 18:11:10 +08:00
if (pagePath.length > 5 && route === '/') {
return pagePath.slice(0, 5) === 'page/';
} else {
return false;
}
});
hexo.extend.helper.register('createNewArchivePosts', function (posts) {
2020-10-27 18:11:10 +08:00
const postList = [], postYearList = [];
posts.forEach(post => postYearList.push(post.date.year()));
Array.from(new Set(postYearList)).forEach(year => {
postList.push({
year: year,
postList: []
})
});
postList.sort((a, b) => b.year - a.year)
postList.forEach(item => {
posts.forEach(post => item.year === post.date.year() && item.postList.push(post))
});
postList.forEach(item => item.postList.sort((a, b) => b.date.unix() - a.date.unix()));
return postList;
});
hexo.extend.helper.register('getLevel', function (postCount) {
return Math.ceil(postCount / 10);
});
const url = require('url');
hexo.extend.helper.register('getPostUrl', function (rootUrl, path) {
if (rootUrl) {
return url.parse(rootUrl).href + path;
} else {
return path;
}
});