diff --git a/app/bot/[username]/status/[id]/page.tsx b/app/bot/[username]/status/[id]/page.tsx index bbfdacf..7cfd3ce 100644 --- a/app/bot/[username]/status/[id]/page.tsx +++ b/app/bot/[username]/status/[id]/page.tsx @@ -9,7 +9,14 @@ export async function generateMetadata({ params, }: PageProps): Promise { const { username, id } = params; - const { text, user, photos, video } = await fetchTweet(id); + let { text, user, photos, video, media } = await fetchTweet(id); + + if (media) { + media.map( + (item: any) => + (text = text.replace(new RegExp("\\s*" + item.url + "\\s*", "g"), "")) + ); + } const photoUrls: string[] = []; photos.map((photo) => photoUrls.push(photo.url)); diff --git a/lib/fetchTweet.ts b/lib/fetchTweet.ts index 6d62cec..492d269 100644 --- a/lib/fetchTweet.ts +++ b/lib/fetchTweet.ts @@ -3,11 +3,18 @@ export async function fetchTweet(id: string): Promise<{ user: any; photos: any[]; video: any | undefined; + media: any | undefined; }> { const baseUrl = "https://cdn.syndication.twimg.com/tweet-result"; const res = await fetch(`${baseUrl}?id=${id}`); const data = await res.json(); - const { text, user, photos, video } = data; - return { text, user, photos: photos ? photos : [], video }; + const { text, user, photos, video, entities } = data; + return { + text, + user, + photos: photos ? photos : [], + video, + media: entities.media, + }; }