|
@@ -22,6 +22,12 @@ const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const isAttachmentLink = (href: string): boolean => {
|
|
|
|
|
+ // see: https://regex101.com/r/9qZhiK/1
|
|
|
|
|
+ const attachmentUrlFormat = new RegExp(/^\/(attachment)\/([^/^\n]+)$/);
|
|
|
|
|
+ return attachmentUrlFormat.test(href);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
type Props = Omit<LinkProps, 'href'> & {
|
|
type Props = Omit<LinkProps, 'href'> & {
|
|
|
children: React.ReactNode,
|
|
children: React.ReactNode,
|
|
|
href?: string,
|
|
href?: string,
|
|
@@ -59,6 +65,13 @@ export const NextLink = (props: Props): JSX.Element => {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // when href is an attachment link
|
|
|
|
|
+ if (isAttachmentLink(href)) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <a href={href} className={className} {...dataAttributes}>{children}</a>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<Link {...rest} href={href} prefetch={false} legacyBehavior>
|
|
<Link {...rest} href={href} prefetch={false} legacyBehavior>
|
|
|
<a href={href} className={className} {...dataAttributes}>{children}</a>
|
|
<a href={href} className={className} {...dataAttributes}>{children}</a>
|