From ab2f61824db22412f45e14b012fa7e57d0cffff7 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 9 Jan 2023 16:25:26 +0000 Subject: [PATCH] feat: output quote data for twitter and jike --- lib/utils/render.js | 1 + lib/v2/jike/user.js | 32 ++++++++++++++++++++------------ lib/v2/twitter/utils.js | 9 +++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/utils/render.js b/lib/utils/render.js index 978eca4d48..35d7159daf 100644 --- a/lib/utils/render.js +++ b/lib/utils/render.js @@ -41,6 +41,7 @@ const json = (data) => { }, ] : undefined, + _extra: item._extra || undefined, })), }; return JSON.stringify(jsonFeed, null, 4); diff --git a/lib/v2/jike/user.js b/lib/v2/jike/user.js index 85612e772a..9f226f3ff2 100644 --- a/lib/v2/jike/user.js +++ b/lib/v2/jike/user.js @@ -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 = `${item.linkInfo.title}
`; @@ -58,6 +59,7 @@ module.exports = async (ctx) => { content = `${content}

`; } + let repostContent; if (item.type === 'REPOST') { const screenNameTemplate = item.target.user ? `@${item.target.user.screenName}` : ''; @@ -67,7 +69,7 @@ module.exports = async (ctx) => { repostImgTemplate += `
`; }); - const repostContent = `转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}`.replace(/\r\n|\n|\r/g, '
'); + repostContent = `
转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}
`.replace(/\r\n|\n|\r/g, '
'); content = `${content}${repostContent}`; } // 部分功能未知 @@ -105,7 +107,13 @@ module.exports = async (ctx) => { title: `${typeMap[item.type]}了: ${shortenTitle}`, description: `${content}${linkTemplate}${imgTemplate}`.replace(/(
|\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') { diff --git a/lib/v2/twitter/utils.js b/lib/v2/twitter/utils.js index 1caabbe816..15a2c9737a 100644 --- a/lib/v2/twitter/utils.js +++ b/lib/v2/twitter/utils.js @@ -205,6 +205,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { if (quoteData) { quoteData.full_text = quoteData.full_text || quoteData.text; const author = quoteData.user; + quote += '
'; if (readable) { quote += `
`; quote += `
`; @@ -260,6 +261,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { if (readable) { quote += `
`; } + quote += '
'; } 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, + }, + }, }; }); };