Просмотр исходного кода

Merge pull request #7430 from ykanematsu/fix/7405-with-2529

imprv: Add cloud icon to download for attachments
Ryoji Shimizu 3 лет назад
Родитель
Сommit
da0690d451
1 измененных файлов с 19 добавлено и 0 удалено
  1. 19 0
      packages/app/src/components/ReactMarkdownComponents/NextLink.tsx

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

@@ -22,6 +22,11 @@ const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
   }
   }
 };
 };
 
 
+const isAttached = (href: string): boolean => {
+    return href.toString().startsWith('/attachment/');
+};
+
+
 type Props = Omit<LinkProps, 'href'> & {
 type Props = Omit<LinkProps, 'href'> & {
   children: React.ReactNode,
   children: React.ReactNode,
   href?: string,
   href?: string,
@@ -59,6 +64,20 @@ export const NextLink = (props: Props): JSX.Element => {
     );
     );
   }
   }
 
 
+  // when href is an attachment file
+  if (isAttached(href)) {
+    const dlhref=href.toString().replace('/attachment/','/download/');
+    return (
+      <span>
+        <a href={href} className={className} target="_blank" rel="noopener noreferrer" {...dataAttributes}>
+        {children}
+        </a>&nbsp;
+        <a href={dlhref} className="attachment-download"><i className='icon-cloud-download'></i></a>
+      </span>
+    );
+  }
+
+
   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>