1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-13 19:55:26 -04:00

use slightly more elegant way of formulating rel attribute of links

This commit is contained in:
2022-07-30 17:05:15 -04:00
parent f49cd3927c
commit 0a9391ed5f
3 changed files with 33 additions and 22 deletions
+6 -1
View File
@@ -1,4 +1,5 @@
import NextLink from "next/link";
import objStr from "obj-str";
import { styled, theme } from "../../lib/styles/stitches.config";
import { baseUrl } from "../../lib/config";
import type { ComponentProps } from "react";
@@ -49,7 +50,11 @@ const Link = ({ href, rel, target, prefetch = false, underline = true, openInNew
<StyledLink
href={href}
target={target || "_blank"}
rel={`${rel || ""} noopener ${isExternal ? "noreferrer" : ""}`.trim()}
rel={objStr({
[`${rel}`]: rel, // prepend whatever string is passed via optional `rel` prop
noopener: true,
noreferrer: isExternal, // don't add "noreferrer" if link isn't external, and only opening in a new tab
})}
underline={underline}
{...rest}
/>