feat(core): 增加 sorted 参数来控制结果排序 (#10744)

* feat: 增加 `sorted` 参数来控制结果排序

* feat: 添加 `sorted` 参数的测试

重用了 `sort` 的代码和数据:是不是可以考虑将两者结合?
This commit is contained in:
Charlie Jiang
2022-09-09 00:11:18 +08:00
committed by GitHub
parent 6de48c433f
commit 655b899715
4 changed files with 27 additions and 1 deletions

View File

@@ -54,7 +54,9 @@ module.exports = async (ctx, next) => {
ctx.state.data.description && (ctx.state.data.description = entities.decodeXML(ctx.state.data.description + ''));
// sort items
ctx.state.data.item = ctx.state.data.item.sort((a, b) => +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));
if (ctx.query.sorted !== 'false') {
ctx.state.data.item = ctx.state.data.item.sort((a, b) => +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));
}
const handleItem = (item) => {
item.title && (item.title = entities.decodeXML(item.title + ''));