mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 05:36:08 +08:00
feat: infoq richContent simple render (#4684)
This commit is contained in:
@@ -26,7 +26,7 @@ const ProcessFeed = async (list, cache) => {
|
||||
|
||||
return {
|
||||
title: data.article_title,
|
||||
description: data.content,
|
||||
description: parseContent(data.content),
|
||||
pubDate,
|
||||
author: author,
|
||||
link,
|
||||
@@ -40,6 +40,60 @@ const ProcessFeed = async (list, cache) => {
|
||||
return items;
|
||||
};
|
||||
|
||||
const parseToSimpleText = (content) => parseToSimpleTexts(content).join('');
|
||||
const parseToSimpleTexts = (content) =>
|
||||
content.map((i) => {
|
||||
const funcMaps = {
|
||||
doc: () =>
|
||||
parseToSimpleTexts(i.content)
|
||||
.map((v) => `<p>${v}</p>`)
|
||||
.join(''),
|
||||
text: () => i.text,
|
||||
heading: () => {
|
||||
const level = i.attrs.level;
|
||||
const text = parseToSimpleText(i.content);
|
||||
return `<h${level}>${text}</h${level}>`;
|
||||
},
|
||||
blockquote: () => {
|
||||
const text = parseToSimpleText(i.content);
|
||||
return `<blockquote>${text}</blockquote>`;
|
||||
},
|
||||
image: () => {
|
||||
const img = i.attrs.src;
|
||||
return `<img src="${img}"></img>`;
|
||||
},
|
||||
codeblock: () => {
|
||||
const lang = i.attrs.lang;
|
||||
const code = parseToSimpleText(i.content);
|
||||
return `<code lang="${lang}">${code}</code>`;
|
||||
},
|
||||
link: () => {
|
||||
const href = i.attrs.href;
|
||||
const text = parseToSimpleText(i.content);
|
||||
return `<a href="${href}">${text}</a>"`;
|
||||
},
|
||||
};
|
||||
|
||||
if (i.type in funcMaps) {
|
||||
return funcMaps[i.type]();
|
||||
}
|
||||
|
||||
if (!i.content) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return parseToSimpleText(i.content);
|
||||
});
|
||||
|
||||
function parseContent(content) {
|
||||
const isRichContent = content.startsWith(`{"`);
|
||||
if (!isRichContent) {
|
||||
return content;
|
||||
}
|
||||
|
||||
return parseToSimpleText([JSON.parse(content)]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ProcessFeed,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user