From f27a13cba9ac1686648d62a8be0ef9d1f3fe65db Mon Sep 17 00:00:00 2001 From: Derek Date: Tue, 15 May 2018 22:23:03 +0800 Subject: [PATCH] fix answer page ref link (#134) --- routes/jike/user.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/routes/jike/user.js b/routes/jike/user.js index 23e0c4523..a6680e625 100644 --- a/routes/jike/user.js +++ b/routes/jike/user.js @@ -36,7 +36,8 @@ module.exports = async (ctx) => { const linkMap = { 'OFFICIAL_MESSAGE': `https://web.okjike.com/message-detail/${item.id}/officialMessage`, 'ORIGINAL_POST': `https://web.okjike.com/post-detail/${item.id}/originalPost`, - 'REPOST': `https://web.okjike.com/post-detail/${item.id}/repost` + 'REPOST': `https://web.okjike.com/post-detail/${item.id}/repost`, + 'ANSWER': `https://m.okjike.com/answers/${item.id}` }; let linkTemplate = ''; @@ -58,17 +59,41 @@ module.exports = async (ctx) => { } if (item.type === 'REPOST') { - const screenNameTemplate = item.target.user ? `@${item.target.user.screenName}`: ''; + const screenNameTemplate = item.target.user ? `@${item.target.user.screenName}` : ''; let repostImgTemplate = ''; item.target.pictures && item.target.pictures.forEach((item) => { repostImgTemplate += `
`; }); - let repostContent = `转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}`; + const repostContent = `转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}`; content = `${content}${repostContent}`.replace(/\n|\r/g, '
'); } + if (item.type === 'ANSWER') { + let answerTextTemplate = ''; + let answerImgTemplate = ''; + let answerImgKeys = []; + item.richtextContent.blocks && item.richtextContent.blocks.forEach((item) => { + if (item.entityRanges.length && item.text === '[图片]') { + answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)]; + } else { + answerTextTemplate += item.text; + } + }); + + if (answerImgKeys.length) { + answerImgKeys.forEach((key) => { + const entity = item.richtextContent.entityMap[key]; + if (entity.type.toUpperCase() === 'IMAGE') { + answerImgTemplate += `
`; + } + }); + } + const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`; + content = `${content}${answerContent}`.replace(/\n|\r/g, '
'); + } + return { title: `${typeMap[item.type]}了: ${shortenTitle}`, description: `${content}${linkTemplate}${imgTemplate}`,