From acf59ee40edbd208c73d57a77222a3a90dec3a6b Mon Sep 17 00:00:00 2001 From: Jebbs Date: Mon, 8 Jan 2024 12:49:17 +0800 Subject: [PATCH] fix: zhihu timeline (#14169) * fix zhihu timeline * deal with content in an array * adopt content_html if exists --- lib/v2/zhihu/timeline.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/v2/zhihu/timeline.js b/lib/v2/zhihu/timeline.js index ed648dc19..67162a370 100644 --- a/lib/v2/zhihu/timeline.js +++ b/lib/v2/zhihu/timeline.js @@ -53,13 +53,28 @@ module.exports = async (ctx) => { return actors.map((e) => e.name).join(', '); }; + const getContent = (content) => { + if (!content || !Array.isArray(content)) { + return content; + } + // content can be a string or an array of objects + return ( + content + .map((e) => e.content) + .filter((e) => e instanceof String && !!e) + // some content may not be wrapped in tag, it will cause error when parsing + .map((e) => `
${e}
`) + .join('') + ); + }; + const buildItem = (e) => { if (!e || !e.target) { return {}; } return { title: `${e.action_text_tpl.replace('{}', buildActors(e))}: ${getOne([e.target.title, e.target.question ? e.target.question.title : ''])}`, - description: utils.ProcessImage(getOne([e.target.content, e.target.detail, e.target.excerpt, ''])), + description: utils.ProcessImage(`
${getOne([e.target.content_html, getContent(e.target.content), e.target.detail, e.target.excerpt, ''])}
`), pubDate: parseDate(e.updated_time * 1000), link: buildLink(e), author: e.target.author ? e.target.author.name : '',