fix: archive 归档页面排序错乱的 bug

This commit is contained in:
XPoet 2020-03-30 11:07:57 +08:00
parent 5b1ee57c60
commit a381f3b419
2 changed files with 4 additions and 1 deletions

View File

@ -20,6 +20,7 @@ page:
right_side_width: 70 right_side_width: 70
media_max_width: 960 media_max_width: 960
# Social Links. # Social Links.
# Usage: `Key: permalink || icon` # Usage: `Key: permalink || icon`
# Key is the link label showing to end users. # Key is the link label showing to end users.
@ -43,6 +44,7 @@ social:
# https://github.com/chriskempson/tomorrow-theme # https://github.com/chriskempson/tomorrow-theme
highlight_theme: normal highlight_theme: normal
# Valine. # Valine.
# You can get your appid and appkey from https://leancloud.cn # You can get your appid and appkey from https://leancloud.cn
# more info please open https://github.com/xCss/Valine # more info please open https://github.com/xCss/Valine

View File

@ -9,12 +9,13 @@ hexo.extend.helper.register('isInHomePaging', function (pagePath, route) {
hexo.extend.helper.register('createNewArchivePosts', function (posts) { hexo.extend.helper.register('createNewArchivePosts', function (posts) {
const postList = [], postYearList = []; const postList = [], postYearList = [];
posts.forEach(post => postYearList.push(post.date.year())); posts.forEach(post => postYearList.push(post.date.year()));
Array.from(new Set(postYearList)).reverse().forEach(year => { Array.from(new Set(postYearList)).forEach(year => {
postList.push({ postList.push({
year: year, year: year,
postList: [] postList: []
}) })
}); });
postList.sort((a, b) => b.year - a.year);
postList.forEach(item => { postList.forEach(item => {
posts.forEach(post => item.year === post.date.year() && item.postList.push(post)) posts.forEach(post => item.year === post.date.year() && item.postList.push(post))
}); });