fix(route): 知乎 收藏夹 (#7058)

This commit is contained in:
kwafok 2021-03-02 13:05:44 +08:00 committed by GitHub
parent 4e52a65ed0
commit 84def4fe5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const { generateData } = require('./pin/utils');
module.exports = async (ctx) => {
const id = ctx.params.id;
@ -30,17 +31,22 @@ module.exports = async (ctx) => {
const collection_title = $('.CollectionDetailPageHeader-title').text() + ' - 知乎收藏夹';
const collection_description = $('.CollectionDetailPageHeader-description').text();
const generateDataPin = (item) => generateData([item.content])[0];
ctx.state.data = {
title: `${collection_title}`,
link: `https://www.zhihu.com/collection/${id}`,
description: `${collection_description}`,
item:
list &&
list.map((item) => ({
title: `${item.content.type === 'article' ? item.content.title : item.content.question.title}`,
link: `${item.content.url}`,
description: `${item.content.content}`,
pubDate: new Date((item.content.type === 'article' ? item.content.updated : item.content.updated_time) * 1000).toUTCString(),
})),
list.map((item) =>
item.content.type === 'pin'
? generateDataPin(item)
: {
title: `${item.content.type === 'article' ? item.content.title : item.content.question.title}`,
link: `${item.content.url}`,
description: `${item.content.content}`,
pubDate: new Date((item.content.type === 'article' ? item.content.updated : item.content.updated_time) * 1000).toUTCString(),
}
),
};
};