Răsfoiți Sursa

add is attachment link

ryoji-s 3 ani în urmă
părinte
comite
eea975fa29

+ 13 - 0
packages/app/src/components/ReactMarkdownComponents/NextLink.tsx

@@ -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'> & {
   children: React.ReactNode,
   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 (
     <Link {...rest} href={href} prefetch={false} legacyBehavior>
       <a href={href} className={className} {...dataAttributes}>{children}</a>