From fc4817e66957eeddbf5c67c5d64001d7db4f08e2 Mon Sep 17 00:00:00 2001 From: anime Date: Thu, 24 Jul 2025 15:03:03 +0800 Subject: [PATCH] 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. --- components/SmartLink.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 components/SmartLink.js diff --git a/components/SmartLink.js b/components/SmartLink.js new file mode 100644 index 00000000..f2abbc83 --- /dev/null +++ b/components/SmartLink.js @@ -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 ( + + {children} + + ) + } + + return ( + + {children} + + ) +} + +export default SmartLink