feat: improve text output with article preview, quote tweets, and media

Enhance the text output format to show more useful information:

- Article tweets: Show 📰 indicator with title + preview text in feeds,
  full body when reading single tweets
- Quote tweets: Display quoted content with ┌─ QT @user formatting
- Media: Show 🖼️/🎬/🔄 indicators with URLs for photos/videos/GIFs

Also refactors single tweet read to use shared printTweets function
for consistent formatting.
This commit is contained in:
George Zhang
2026-01-11 23:35:03 +00:00
committed by Peter Steinberger
parent de49a66601
commit cf78fce646
4 changed files with 70 additions and 6 deletions
+5
View File
@@ -236,6 +236,11 @@ export interface TweetData {
quotedTweet?: TweetData;
// Media attachments (photos, videos, GIFs)
media?: TweetMedia[];
// Article metadata (for Twitter Articles / long-form posts)
article?: {
title: string;
previewText?: string;
};
// Raw GraphQL tweet result (only when includeRaw is enabled)
_raw?: GraphqlTweetResult;
}
+25
View File
@@ -153,6 +153,29 @@ export function extractTweetText(result: GraphqlTweetResult | undefined): string
return extractArticleText(result) ?? extractNoteTweetText(result) ?? firstText(result?.legacy?.full_text);
}
export function extractArticleMetadata(
result: GraphqlTweetResult | undefined,
): { title: string; previewText?: string } | undefined {
const article = result?.article;
if (!article) {
return undefined;
}
const articleResult = article.article_results?.result ?? article;
const title = firstText(articleResult.title, article.title);
if (!title) {
return undefined;
}
// preview_text is available in home timeline responses
const previewText = firstText(
(articleResult as { preview_text?: string }).preview_text,
(article as { preview_text?: string }).preview_text,
);
return { title, previewText };
}
export function extractMedia(result: GraphqlTweetResult | undefined): TweetMedia[] | undefined {
// Prefer extended_entities (has video info), fall back to entities
const rawMedia = result?.legacy?.extended_entities?.media ?? result?.legacy?.entities?.media;
@@ -261,6 +284,7 @@ export function mapTweetResult(
}
const media = extractMedia(result);
const article = extractArticleMetadata(result);
const tweetData: TweetData = {
id: result.rest_id,
@@ -278,6 +302,7 @@ export function mapTweetResult(
authorId: userId,
quotedTweet,
media,
article,
};
if (includeRaw) {