# Build-Time Embed Architecture for Astro Blog ## Overview Complete solution for embedding tweets, YouTube videos, and other rich content with **full styling control** and **build-time generation**. ## Architecture ### 1. Build-Time Embed Components - **YouTubeEmbed.astro** - Generates iframe at build time - **TwitterEmbed.astro** - Fetches tweet data at build time - **GenericEmbed.astro** - Handles any oEmbed provider - **EmbedContainer.astro** - Wrapper for consistent styling ### 2. Data Flow ``` Build Time: 1. Component receives props (videoId, tweetId, url) 2. Astro fetches embed data/API endpoints 3. Generates HTML with your custom styles 4. Injects into static page Runtime: - No external API calls - Fast loading - Full styling control ``` ### 3. Key Features - ✅ **Build-time generation** - No client-side JS needed - ✅ **Full styling control** - CSS variables + custom classes - ✅ **Lazy loading** - Intersection Observer for performance - ✅ **No paid services** - Uses official APIs only - ✅ **TypeScript support** - Full type safety - ✅ **Responsive** - Mobile-first design ## Implementation Strategy ### YouTube (Simplest) ```astro --- // Build time: Just generate iframe const { videoId, className } = Astro.props; const embedUrl = `https://www.youtube.com/embed/${videoId}`; ---
``` ### Twitter (Requires API) ```astro --- // Build time: Fetch tweet data via Twitter API const { tweetId } = Astro.props; const tweetData = await fetchTweetData(tweetId); // Uses oEmbed or API --- ``` ### Generic (oEmbed) ```astro --- // Build time: Fetch oEmbed data const { url } = Astro.props; const oEmbedData = await fetchOEmbed(url); --- ``` ## File Structure ``` src/ ├── components/ │ └── Embeds/ │ ├── YouTubeEmbed.astro │ ├── TwitterEmbed.astro │ ├── GenericEmbed.astro │ ├── EmbedContainer.astro │ └── index.ts ``` ## Usage Examples ### In MDX/Markdown ```mdx import { YouTubeEmbed, TwitterEmbed } from '../components/Embeds'; # My Blog Post