fix: zhihu timeline (#14169)

* fix zhihu timeline

* deal with content in an array

* adopt content_html if exists
This commit is contained in:
Jebbs
2024-01-08 12:49:17 +08:00
committed by GitHub
parent 64d87889de
commit acf59ee40e
+16 -1
View File
@@ -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) => `<div>${e}</div>`)
.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(`<div>${getOne([e.target.content_html, getContent(e.target.content), e.target.detail, e.target.excerpt, ''])}</div>`),
pubDate: parseDate(e.updated_time * 1000),
link: buildLink(e),
author: e.target.author ? e.target.author.name : '',