feat: output quote data for twitter and jike

This commit is contained in:
DIYgod
2023-01-09 16:25:26 +00:00
parent 350dfa4535
commit ab2f61824d
3 changed files with 30 additions and 12 deletions

View File

@@ -41,6 +41,7 @@ const json = (data) => {
},
]
: undefined,
_extra: item._extra || undefined,
})),
};
return JSON.stringify(jsonFeed, null, 4);

View File

@@ -18,6 +18,17 @@ module.exports = async (ctx) => {
const raw = $('[type = "application/json"]').html();
const data = JSON.parse(raw).props.pageProps;
const getLink = (id, type) => {
switch (type) {
case 'REPOST':
return `https://m.okjike.com/reposts/${id}`;
case 'MEDIUM':
return `https://www.okjike.com/medium/${id}`;
default:
return `https://m.okjike.com/originalPosts/${id}`;
}
};
const items = await Promise.all(
data.posts.map(async (item) => {
const typeMap = {
@@ -28,16 +39,6 @@ module.exports = async (ctx) => {
PERSONAL_UPDATE: '创建新主题',
};
const linkMap = {
ORIGINAL_POST: `https://m.okjike.com/originalPosts/${item.id}`,
REPOST: `https://m.okjike.com/reposts/${item.id}`,
MEDIUM: `https://www.okjike.com/medium/${item.id}`,
// OFFICIAL_MESSAGE: `https://m.okjike.com/originalPosts/${item.id}`,
// ANSWER: `https://m.okjike.com/answer/${item.id}`,
// QUESTION: `https://m.okjike.com/originalPosts/${item.id}`,
// PERSONAL_UPDATE: `https://m.okjike.com/topic/${item.id}${item.topic && item.topic.id}`,
};
let linkTemplate = '';
if (item.linkInfo && item.linkInfo.linkUrl) {
linkTemplate = `<a href="${item.linkInfo.linkUrl}">${item.linkInfo.title}</a><br>`;
@@ -58,6 +59,7 @@ module.exports = async (ctx) => {
content = `${content}<br><br>`;
}
let repostContent;
if (item.type === 'REPOST') {
const screenNameTemplate = item.target.user ? `<a href="https://m.okjike.com/users/${item.target.user.username}" target="_blank">@${item.target.user.screenName}</a>` : '';
@@ -67,7 +69,7 @@ module.exports = async (ctx) => {
repostImgTemplate += `<br><img src="${item.thumbnailUrl}">`;
});
const repostContent = `转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}`.replace(/\r\n|\n|\r/g, '<br>');
repostContent = `<div class="rsshub-quote">转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}</div>`.replace(/\r\n|\n|\r/g, '<br>');
content = `${content}${repostContent}`;
}
// 部分功能未知
@@ -105,7 +107,13 @@ module.exports = async (ctx) => {
title: `${typeMap[item.type]}了: ${shortenTitle}`,
description: `${content}${linkTemplate}${imgTemplate}`.replace(/(<br>|\s)+$/, ''),
pubDate: parseDate(item.createdAt),
link: linkMap[item.type],
link: getLink(item.id, item.type),
_extra: repostContent && {
quote: {
url: getLink(item.target.id, item.target.type),
content_html: repostContent,
},
},
};
if (id === 'wenhao1996' && item.topic.id === '553870e8e4b0cafb0a1bef68') {

View File

@@ -205,6 +205,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
if (quoteData) {
quoteData.full_text = quoteData.full_text || quoteData.text;
const author = quoteData.user;
quote += '<div class="rsshub-quote">';
if (readable) {
quote += `<br clear='both' /><div style='clear: both'></div>`;
quote += `<blockquote style='background: #80808010;border-top:1px solid #80808030;border-bottom:1px solid #80808030;margin:0;padding:5px 20px;'>`;
@@ -260,6 +261,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
if (readable) {
quote += `</blockquote>`;
}
quote += '</div>';
} else {
url = formatUrl(item);
}
@@ -382,6 +384,13 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => {
description,
pubDate: parseDate(item.created_at),
link: `https://twitter.com/${item.user.screen_name}/status/${item.id_str}`,
_extra: item.is_quote_status && {
quote: {
url: `https://twitter.com/${item.quoted_status.user?.screen_name}/status/${item.quoted_status.id_str}`,
content_html: quote,
},
},
};
});
};