From 1c20fbb966177f3da28b11d1ba91f55434f8107a Mon Sep 17 00:00:00 2001 From: DJIBRILDIA Date: Tue, 5 Dec 2023 12:18:13 +0100 Subject: [PATCH] fix(ui): support long links --- src/components/a.tsx | 132 ++++++++++++++++++++++------------------- src/utils/markdown.tsx | 2 +- 2 files changed, 72 insertions(+), 62 deletions(-) diff --git a/src/components/a.tsx b/src/components/a.tsx index 075b6713..65410450 100644 --- a/src/components/a.tsx +++ b/src/components/a.tsx @@ -21,67 +21,77 @@ const Anchor = ({ } & LinkProps & { icon?: string; iconPosition?: 'first' | 'last'; - } & Exclude, 'href'>) => ( - - , 'href'>) => { + const isURLLink = + href.length > 30 && + children instanceof Array && + typeof children[0] === 'string' && + href === children[0]; + + return ( + - {icon ? : null} - {children} - - - -); + + {icon ? : null} + {isURLLink + ? [href.replace(/(http|ftp)s?:\/\//, '').slice(0, 15) + '…' + href.slice(-5)] + : children} + + + + ); +}; export default Anchor; diff --git a/src/utils/markdown.tsx b/src/utils/markdown.tsx index cbc0b3cc..b4f780f4 100644 --- a/src/utils/markdown.tsx +++ b/src/utils/markdown.tsx @@ -182,7 +182,7 @@ const headingMap: NodeToElementMapper = ( ); }; const textMap: NodeToElementMapper = (context, node) => ( - {fixText(node.value)} + fixText(node.value) ); const boldMap: NodeToElementMapper = (context, node) => (