feat: enhance MDX link component with external link detection

This commit is contained in:
2026-06-01 21:35:57 -05:00
parent a7889135a1
commit 6888df0c76

View File

@@ -30,11 +30,20 @@ export function useMDXComponents(components: MDXComponents): MDXComponents {
</blockquote>
),
hr: () => <hr className="my-8 border-border" />,
a: ({ href, children }) => (
<a href={href} className="font-medium underline underline-offset-4 hover:text-accent transition-colors">
{children}
</a>
),
a: ({ href, children, ...props }) => {
const isExternal = typeof href === 'string' && (href.startsWith('http://') || href.startsWith('https://'))
return (
<a
href={href}
target={isExternal ? '_blank' : undefined}
rel={isExternal ? 'noopener noreferrer' : undefined}
className="font-medium underline underline-offset-4 hover:text-accent transition-colors"
{...props}
>
{children}
</a>
)
},
code: ({ children, ...props }) => (
<code
{...props}