feat: enhance MDX link component with external link detection
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user