diff --git a/src/components/shortcodes/LinkCard.astro b/src/components/shortcodes/LinkCard.astro new file mode 100644 index 0000000..8575860 --- /dev/null +++ b/src/components/shortcodes/LinkCard.astro @@ -0,0 +1,239 @@ +--- +interface Props { + url: string; + showArchive?: boolean; + title?: string; + description?: string; + siteName?: string; +} + +const { url, showArchive = true} = Astro.props; + +const siteMetadata = { + title: Astro.props.title || '', + description: Astro.props.description || '', + siteName: Astro.props.siteName || '', + image: '', + domain: new URL(url).hostname || '' +}; + +// Get metadata from the URL +async function fetchMetadata(url: string) { + try { + const response = await fetch(url, { + headers: { + 'User-Agent': 'Mozilla/5.0 (compatible; LinkCard/1.0)' + } + }); + + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + + const html = await response.text(); + + // 提取元数据 + const titleMatch = html.match(/
{metadata.description}
+ )} + + {metadata.siteName && + } +