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>
|
</blockquote>
|
||||||
),
|
),
|
||||||
hr: () => <hr className="my-8 border-border" />,
|
hr: () => <hr className="my-8 border-border" />,
|
||||||
a: ({ href, children }) => (
|
a: ({ href, children, ...props }) => {
|
||||||
<a href={href} className="font-medium underline underline-offset-4 hover:text-accent transition-colors">
|
const isExternal = typeof href === 'string' && (href.startsWith('http://') || href.startsWith('https://'))
|
||||||
{children}
|
return (
|
||||||
</a>
|
<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: ({ children, ...props }) => (
|
||||||
<code
|
<code
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
Reference in New Issue
Block a user