'use client'; import { ExternalLink } from 'lucide-react'; import { cn } from '@/lib/utils'; interface Source { url: string; title?: string; } interface SourcesCompactProps { sources: Source[]; className?: string; } export function SourcesCompact({ sources, className }: SourcesCompactProps) { const getFaviconUrl = (url: string): string => { try { const domain = new URL(url).hostname; return `https://www.google.com/s2/favicons?domain=${domain}&sz=16`; } catch { return ''; } }; const getDomain = (url: string): string => { try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return url.replace(/^https?:\/\//, '').replace(/^www\./, '').split('/')[0]; } }; if (!sources || sources.length === 0) { return null; } return (
{sources.map((source, idx) => { const faviconUrl = getFaviconUrl(source.url); const domain = getDomain(source.url); return ( {faviconUrl ? ( { (e.target as HTMLImageElement).style.display = 'none'; }} /> ) : ( )}
{source.title || domain}
{domain}
); })}
); }