From f4abc22dcb4e53c517b041981802a1b11f36e4d1 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Wed, 2 Feb 2022 23:12:24 +0800 Subject: [PATCH] fix(route): fix zhihu/zhuanlan route is empty and some answer item do not have question.author field (#8952) * Fix(route): fix route is empty * Fix(route): some answer item do not have question.author field * Fix(route): fix route is empty --- lib/routes/zhihu/zhuanlan.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/routes/zhihu/zhuanlan.js b/lib/routes/zhihu/zhuanlan.js index 9deb1e7ad..907685563 100644 --- a/lib/routes/zhihu/zhuanlan.js +++ b/lib/routes/zhihu/zhuanlan.js @@ -14,6 +14,17 @@ module.exports = async (ctx) => { }, }); + const pinnedRes = await got({ + method: 'get', + url: `https://www.zhihu.com/api/v4/columns/${id}/pinned-items`, + headers: { + ...utils.header, + Referer: `https://zhuanlan.zhihu.com/${id}`, + }, + }); + + listRes.data.data = listRes.data.data.concat(pinnedRes.data.data); + // 知乎专栏链接存在两种格式, 一种以 'zhuanlan.' 开头, 另一种新增的以 'c_' 结尾 let url = `https://zhuanlan.zhihu.com/${id}`; if (id.search('c_') === 0) { @@ -41,7 +52,7 @@ module.exports = async (ctx) => { if (item.type === 'answer') { title = item.question.title; - author = item.question.author.name; + author = item.question.author ? item.question.author.name : ''; link = `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`; pubDate = new Date(item.created_time * 1000); } else if (item.type === 'article') {