1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-18 13:45:34 -04:00

allow additional rel info for new tab links

This commit is contained in:
2022-04-29 12:54:35 -04:00
parent f354108b5b
commit 3547d14576
8 changed files with 42 additions and 34 deletions

View File

@@ -50,14 +50,21 @@ const CustomLink = ({
}: CustomLinkProps) => {
// this component auto-detects whether or not we should use a normal HTML anchor externally or next/link internally,
// can be overridden with `forceNewWindow={true}`.
if (forceNewWindow || isAbsoluteUrl(href.toString())) {
const isExternal = isAbsoluteUrl(href.toString());
if (forceNewWindow || isExternal) {
return (
<FancyLink href={href.toString()} target={target || "_blank"} rel={rel || "noopener noreferrer"} {...rest} />
<FancyLink
href={href.toString()}
target={target ?? "_blank"}
rel={[rel, "noopener", isExternal ? "noreferrer" : ""].join(" ").trim()}
{...rest}
/>
);
} else {
return (
<NextLink href={href} prefetch={prefetch} passHref={passHref}>
<FancyLink {...rest} />
<FancyLink target={target} rel={rel} {...rest} />
</NextLink>
);
}