mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 15:09:22 +00:00
feat: add SmartLink component for internal and external links
The component automatically detects link type and applies appropriate rendering with proper attributes for external links.
This commit is contained in:
27
components/SmartLink.js
Normal file
27
components/SmartLink.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import Link from 'next/link'
|
||||
import { siteConfig } from '@/lib/config'
|
||||
|
||||
const SmartLink = ({ href, children, ...rest }) => {
|
||||
const LINK = siteConfig('LINK')
|
||||
const isExternal = href.startsWith('http') && !href.startsWith(LINK)
|
||||
|
||||
if (isExternal) {
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
{...rest}>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Link href={href} {...rest}>
|
||||
{children}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export default SmartLink
|
||||
Reference in New Issue
Block a user