Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Fetch any URL via Chrome CDP and convert the rendered page to clean markdown with YouTube transcript support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/lib/adapters/x/single.ts
1import type { ExtractedDocument, ContentBlock } from "../../extract/document";2import { findTweetNode, formatMediaList, formatTweetAuthor, getTweetAuthorMetadata, normalizeTitle, toXTweet } from "./shared";34export function extractSingleTweetDocumentFromPayload(5payload: unknown,6statusId: string,7pageUrl: string,8): ExtractedDocument | null {9const tweet = findTweetNode(payload, statusId);10if (!tweet) {11return null;12}1314const xTweet = toXTweet(tweet, pageUrl);15const content: ContentBlock[] = [];1617if (xTweet.text) {18content.push({ type: "paragraph", text: xTweet.text });19}2021for (const mediaLine of formatMediaList(xTweet.media)) {22if (mediaLine.startsWith("photo: ")) {23content.push({24type: "image",25url: mediaLine.slice("photo: ".length),26});27} else {28content.push({29type: "list",30ordered: false,31items: [mediaLine],32});33}34}3536if (xTweet.quotedTweet) {37const quotedLines: string[] = [];38const quotedAuthor =39xTweet.quotedTweet.author && xTweet.quotedTweet.authorName40? `${xTweet.quotedTweet.authorName} (@${xTweet.quotedTweet.author})`41: xTweet.quotedTweet.author42? `@${xTweet.quotedTweet.author}`43: xTweet.quotedTweet.authorName;4445if (quotedAuthor) {46quotedLines.push(quotedAuthor);47}48if (xTweet.quotedTweet.text) {49quotedLines.push(xTweet.quotedTweet.text);50}51quotedLines.push(...formatMediaList(xTweet.quotedTweet.media));5253if (quotedLines.length > 0) {54content.push({ type: "heading", depth: 2, text: "Quoted Tweet" });55content.push({ type: "quote", text: quotedLines.join("\n\n") });56}57}5859return {60url: pageUrl,61canonicalUrl: xTweet.url,62title: normalizeTitle(63xTweet.author ? `@${xTweet.author}: ${xTweet.text}` : xTweet.text,64"Tweet",65),66author: formatTweetAuthor(xTweet),67siteName: "X",68publishedAt: xTweet.createdAt,69summary: xTweet.text.slice(0, 200) || undefined,70adapter: "x",71metadata: {72kind: "x/post",73tweetId: xTweet.id,74...getTweetAuthorMetadata(xTweet),75conversationId:76typeof tweet.legacy === "object" &&77tweet.legacy !== null &&78typeof (tweet.legacy as Record<string, unknown>).conversation_id_str === "string"79? (tweet.legacy as Record<string, unknown>).conversation_id_str80: undefined,81favoriteCount: xTweet.likes,82replyCount: xTweet.replies,83retweetCount: xTweet.retweets,84},85content,86};87}88