refactor SiteLink to not repeat (#125)

This commit is contained in:
Sinclair Chen 2022-05-17 10:36:36 -07:00 committed by GitHub
parent f8601af45c
commit 1bf2073e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,24 +9,8 @@ export const SiteLink = (props: {
}) => {
const { href, children, onClick, className } = props
return href.startsWith('http') ? (
<a
href={href}
className={clsx(
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
className
)}
style={{ /* For iOS safari */ wordBreak: 'break-word' }}
target="_blank"
onClick={(e) => {
e.stopPropagation()
if (onClick) onClick()
}}
>
{children}
</a>
) : (
<Link href={href}>
return (
<MaybeLink href={href}>
<a
className={clsx(
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
@ -40,6 +24,15 @@ export const SiteLink = (props: {
>
{children}
</a>
</Link>
</MaybeLink>
)
}
function MaybeLink(props: { href: string; children: React.ReactNode }) {
const { href, children } = props
return href.startsWith('http') ? (
<>{children}</>
) : (
<Link href={href}>{children}</Link>
)
}