'sorter' configuration item
daiwa233 opened this issue · comments
I want to add an article pinning feature base to the plugin. I implemented this feature by modifying the sorter configuration item, but it didn't work, although I recompiled many times.
Below is my configuration about the plugin
[ '@vuepress/blog', { directories: [ { id: 'post', dirname: '_posts', path: '/', layout: 'Layout', itemLayout: 'Post', itemPermalink: '/:regular', pagination: { lengthPerPage: 5, }, sorter: (prev, next) => { if (prev.frontmatter.sticky) return -1; if (next.frontmatter.sticky) return 1; const moment = require('moment'); const prevTime = moment(prev.frontmatter.date).valueOf(); const nextTime = moment(next.frontmatter.date).valueOf(); return prevTime - nextTime > 0 ? -1 : 1; } }, ], } ]
Please follow the issue template and give the code a bit format to improve readability.
You probably misunderstand the config, try:
directories: [
{
...
pagination:{
sorter: (prev, next) => {
if (prev.frontmatter.sticky) return -1;
if (next.frontmatter.sticky) return 1;
const dayjs = require('dayjs');
const prevTime = dayjs(prev.frontmatter.date)
const nextTime = dayjs(next.frontmatter.date)
return prevTime - nextTime > 0 ? -1 : 1;
}
}
},
],
oops! thank you