From 84def4fe5df870054b2bf9c2e772900ff1910d71 Mon Sep 17 00:00:00 2001 From: kwafok Date: Tue, 2 Mar 2021 13:05:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E7=9F=A5=E4=B9=8E=20=E6=94=B6?= =?UTF-8?q?=E8=97=8F=E5=A4=B9=20(#7058)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/zhihu/collection.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/routes/zhihu/collection.js b/lib/routes/zhihu/collection.js index 18f33f6b8..3cb2610d8 100644 --- a/lib/routes/zhihu/collection.js +++ b/lib/routes/zhihu/collection.js @@ -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(), + } + ), }; };