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 <hr> 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 <i@rong.moe>
This commit is contained in:
Rongrong 2024-01-21 14:14:19 +00:00 committed by GitHub
parent 1e7793e0ef
commit 4644ce5755
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 3 deletions

View File

@ -31,9 +31,11 @@ const replaceBreak = (text) => text.replaceAll(/<br><br>|<br>/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 += `<br clear='both' /><div style='clear: both'></div><hr>`;
description += `<br clear='both' /><div style='clear: both'></div>`;
}
if (showTimestampInDescription) {
if (readable) {
description += `<hr>`;
}
description += `<small>${parseDate(item.created_at)}</small>`;
}
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 && {