From 4644ce575565c8205cc29aca921282e1b07f24c2 Mon Sep 17 00:00:00 2001 From: Rongrong Date: Sun, 21 Jan 2024 14:14:19 +0000 Subject: [PATCH] fix(route/twitter): readability and RT link (#14289) 1. Trim link pointing to the tweet itself (usually appears when the tweet is truncated). 2. Only insert
when both showTimestampInDescription and readable are enabled. 3. Make RT links point to the RT itself, instead of the original tweet. Signed-off-by: Rongrong --- lib/v2/twitter/utils.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/v2/twitter/utils.js b/lib/v2/twitter/utils.js index 15a3924e2..36fb991df 100644 --- a/lib/v2/twitter/utils.js +++ b/lib/v2/twitter/utils.js @@ -31,9 +31,11 @@ const replaceBreak = (text) => text.replaceAll(/

|
/g, ' '); const formatText = (item) => { let text = item.full_text; + const id_str = item.id_str || item.conversation_id_str; const urls = item.entities.urls || []; for (const url of urls) { - text = text.replaceAll(url.url, url.expanded_url); + // trim link pointing to the tweet itself (usually appears when the tweet is truncated) + text = text.replaceAll(url.url, url.expanded_url.endsWith(id_str) ? '' : url.expanded_url); } const media = item.extended_entities?.media || []; for (const m of media) { @@ -361,20 +363,27 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { description += quote; if (readable) { - description += `

`; + description += `
`; } if (showTimestampInDescription) { + if (readable) { + description += `
`; + } description += `${parseDate(item.created_at)}`; } const authorName = originalItem.user.name; + const link = + originalItem.user.screen_name && (originalItem.id_str || originalItem.conversation_id_str) + ? `https://twitter.com/${originalItem.user.screen_name}/status/${originalItem.id_str || originalItem.conversation_id_str}` + : `https://twitter.com/${item.user.screen_name}/status/${item.id_str || item.conversation_id_str}`; return { title, author: authorName, description, pubDate: parseDate(item.created_at), - link: `https://twitter.com/${item.user.screen_name}/status/${item.id_str || item.conversation_id_str}`, + link, _extra: (isRetweet && {