🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor LandingPageTemplate and enhance Tweet component normalization
Bill Yange553dd33e061
diff --git a/docs/src/components/LandingPageTemplate.tsx b/docs/src/components/LandingPageTemplate.tsxindex 9e407d58b..59125be33 100644--- a/docs/src/components/LandingPageTemplate.tsx+++ b/docs/src/components/LandingPageTemplate.tsx@@ -93,11 +93,7 @@ interface LandingPageTemplateProps {showEUFlag?: boolean;}-export function LandingPageTemplate({- title,- subtitle,- showEUFlag = true,-}: LandingPageTemplateProps) {+export function LandingPageTemplate({ title, subtitle, showEUFlag = true }: LandingPageTemplateProps) {const t = useExtracted();const features = [@@ -298,9 +294,7 @@ export function LandingPageTemplate({<Icon size={20} className="text-neutral-600 dark:text-neutral-400" />{feature.title}</h3>- <p className="text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed">- {feature.description}- </p>+ <p className="text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed">{feature.description}</p></div>);})}@@ -365,16 +359,15 @@ export function LandingPageTemplate({<TweetCard id="1920899082253434950" /><TweetCard id="2000788904778326334" /><TweetCard id="2015102995789381815" />- <TweetCard id="1982378431166963982" /><TweetCard id="1980082738934993142" /><TweetCard id="1976495558480232672" /></Marquee>{/* Column 3 - hidden on mobile */}<Marquee vertical pauseOnHover className="hidden md:flex [--duration:60s]" repeat={2}>+ <TweetCard id="1982378431166963982" /><TweetCard id="2009548405488615871" /><TweetCard id="1920470706761929048" />- <TweetCard id="1981795864118243355" /><TweetCard id="1979830490006974510" /><TweetCard id="1970265809122705759" /></Marquee>diff --git a/docs/src/components/Tweet.tsx b/docs/src/components/Tweet.tsxindex 4efc69eaf..323ddabfd 100644--- a/docs/src/components/Tweet.tsx+++ b/docs/src/components/Tweet.tsx@@ -5,6 +5,41 @@ import { enrichTweet, type TweetProps } from "react-tweet";import { getTweet, type Tweet } from "react-tweet/api";import { TweetBody, TweetHeader, TweetMedia } from "./TweetClient";+type TweetEntityBuckets = Partial<Record<keyof Tweet["entities"], unknown>>;++const getEntityBucket = <Key extends keyof Tweet["entities"]>(+ entities: TweetEntityBuckets | null | undefined,+ key: Key+): NonNullable<Tweet["entities"][Key]> => {+ const bucket = entities?.[key];+ return (Array.isArray(bucket) ? bucket : []) as NonNullable<Tweet["entities"][Key]>;+};++const normalizeTweetEntities = (entities: TweetEntityBuckets | null | undefined): Tweet["entities"] => {+ const media = getEntityBucket(entities, "media");++ return {+ hashtags: getEntityBucket(entities, "hashtags"),+ urls: getEntityBucket(entities, "urls"),+ user_mentions: getEntityBucket(entities, "user_mentions"),+ symbols: getEntityBucket(entities, "symbols"),+ ...(media.length > 0 ? { media } : {}),+ };+};++const normalizeTweetForEnrichment = (tweet: Tweet): Tweet => ({+ ...tweet,+ entities: normalizeTweetEntities(tweet.entities),+ ...(tweet.quoted_tweet+ ? {+ quoted_tweet: {+ ...tweet.quoted_tweet,+ entities: normalizeTweetEntities(tweet.quoted_tweet.entities),+ },+ }+ : {}),+});+const Skeleton = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => {return <div className={cn("rounded-md bg-primary/10", className)} {...props} />;};@@ -29,7 +64,7 @@ export const TweetNotFound = ({ className, ...props }: { className?: string; [ke);export const MagicTweet = ({ tweet, className, ...props }: { tweet: Tweet; className?: string }) => {- const enrichedTweet = enrichTweet(tweet);+ const enrichedTweet = enrichTweet(normalizeTweetForEnrichment(tweet));return (<divclassName={cn(