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

less resource-intensive methods of parsing URLs

This commit is contained in:
2022-06-01 18:40:57 -04:00
parent d1ee8b2632
commit 33c210aacf
16 changed files with 195 additions and 188 deletions
+2 -2
View File
@@ -46,14 +46,14 @@ export type LinkProps = Omit<ComponentProps<typeof StyledLink>, "href"> &
const Link = ({ href, rel, target, prefetch = false, underline = true, openInNewTab, ...rest }: LinkProps) => {
// This component auto-detects whether or not this link should open in the same window (the default for internal
// links) or a new tab (the default for external links). Defaults can be overridden with `openInNewTab={true}`.
const isExternal = typeof href === "string" ? new URL(href as string, baseUrl).origin !== baseUrl : false;
const isExternal = typeof href === "string" && !href.startsWith("/") && !href.startsWith(baseUrl);
if (openInNewTab || isExternal) {
return (
<StyledLink
href={href}
target={target || "_blank"}
rel={[rel, "noopener", isExternal ? "noreferrer" : ""].join(" ").trim()}
rel={`${rel || ""} noopener ${isExternal ? "noreferrer" : ""}`.trim()}
underline={underline}
{...rest}
/>