import React from 'react'; interface GenericEmbedProps { url: string; className?: string; maxWidth?: string; type?: 'video' | 'article' | 'rich'; } export const GenericEmbed: React.FC = ({ url, className = "", maxWidth = "100%", type = 'rich' }) => { let embedUrl: string | null = null; let provider = 'unknown'; try { const urlObj = new URL(url); const hostname = urlObj.hostname.replace('www.', ''); if (hostname.includes('youtube.com') || hostname.includes('youtu.be')) { const videoId = urlObj.searchParams.get('v') || urlObj.pathname.split('/').pop(); if (videoId) { embedUrl = `https://www.youtube.com/embed/${videoId}`; provider = 'youtube.com'; } } else if (hostname.includes('vimeo.com')) { const videoId = urlObj.pathname.split('/').filter(Boolean)[0]; if (videoId) { embedUrl = `https://player.vimeo.com/video/${videoId}`; provider = 'vimeo.com'; } } else if (hostname.includes('codepen.io')) { const penPath = urlObj.pathname.replace('/pen/', '/'); embedUrl = `https://codepen.io${penPath}?default-tab=html,result`; provider = 'codepen.io'; } else if (hostname.includes('gist.github.com')) { const gistPath = urlObj.pathname; embedUrl = `https://gist.github.com${gistPath}.js`; provider = 'gist.github.com'; } } catch (e) { console.warn('GenericEmbed: Failed to parse URL', e); } const hasEmbed = embedUrl !== null; return (
{hasEmbed ? (
{type === 'video' ? (