diff --git a/docs/social-media.md b/docs/social-media.md index cd624aa97..73ae5cb2f 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -1094,7 +1094,7 @@ rule ### 收藏夹 - + ### 用户动态 diff --git a/lib/routes/zhihu/collection.js b/lib/routes/zhihu/collection.js index 173e582d6..18f33f6b8 100644 --- a/lib/routes/zhihu/collection.js +++ b/lib/routes/zhihu/collection.js @@ -6,6 +6,17 @@ module.exports = async (ctx) => { const id = ctx.params.id; const response = await got({ + method: 'get', + url: `https://www.zhihu.com/api/v4/collections/${id}/items?offset=0&limit=20`, + headers: { + ...utils.header, + Referer: `https://www.zhihu.com/collection/${id}`, + }, + }); + + const list = response.data.data; + + const response2 = await got({ method: 'get', url: `https://www.zhihu.com/collection/${id}`, headers: { @@ -14,31 +25,22 @@ module.exports = async (ctx) => { }, }); - const data = response.data; - const $ = cheerio.load(data); - const list = $('.CollectionDetailPageItem'); + const meta = response2.data; + const $ = cheerio.load(meta); + const collection_title = $('.CollectionDetailPageHeader-title').text() + ' - 知乎收藏夹'; + const collection_description = $('.CollectionDetailPageHeader-description').text(); ctx.state.data = { - title: $('title').text(), + title: `${collection_title}`, link: `https://www.zhihu.com/collection/${id}`, - description: $('.CollectionDetailPageHeader-description').text(), + description: `${collection_description}`, item: list && - list - .map((index, item) => { - const $item = $(item); - const $title = $item.find('.ContentItem-title a'); - const linkUrl = new URL($title.attr('href'), 'https://www.zhihu.com/'); - const image = $item.find('meta[itemprop="image"]').attr('content'); - const text = $item.find('.CopyrightRichText-richText').text(); - const content = image ? text + `` : text; - - return { - title: $title.text(), - description: content, - link: linkUrl, - }; - }) - .get(), + 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(), + })), }; };