The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
use linkify
Steven Tey677cbf523d20
diff --git a/apps/web/package.json b/apps/web/package.jsonindex be2e472d71..628efe37e0 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -52,6 +52,8 @@"he": "^1.2.0","html-escaper": "^3.0.3","js-cookie": "^3.0.5",+ "linkify-react": "^4.1.3",+ "linkifyjs": "^4.1.3","lucide-react": "^0.299.0","nanoid": "^5.0.1","next": "14.0.4-canary.39",diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsxindex bb6776017d..f10e8aefdc 100644--- a/apps/web/ui/links/link-card.tsx+++ b/apps/web/ui/links/link-card.tsx@@ -44,10 +44,10 @@ import {} from "lucide-react";import Link from "next/link";import { useParams } from "next/navigation";+import Linkify from "linkify-react";import punycode from "punycode/";import { useContext, useEffect, useMemo, useRef, useState } from "react";import useSWR from "swr";-import { LinkifyComments } from "@dub/ui"export default function LinkCard({props,@@ -303,9 +303,16 @@ export default function LinkCard({<Tooltipcontent={<div className="block max-w-sm px-4 py-2 text-center text-sm text-gray-700">- <LinkifyComments>- {comments}- </LinkifyComments>+ <Linkify+ as="p"+ options={{+ rel: "noopener noreferrer nofollow",+ className:+ "underline underline-offset-4 text-gray-400 hover:text-gray-700",+ }}+ >+ {comments}+ </Linkify></div>}>diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsxindex 38d0948583..08c72bdb7e 100644--- a/packages/ui/src/index.tsx+++ b/packages/ui/src/index.tsx@@ -11,7 +11,6 @@ export * from "./modal";export * from "./popover";export * from "./switch";export * from "./tooltip";-export * from "./linkify-comments"// hooksexport * from "./hooks";@@ -35,4 +34,3 @@ export * from "./icon-menu";export * from "./inline-snippet";export * from "./link-preview";export * from "./tab-select";-diff --git a/packages/ui/src/linkify-comments.tsx b/packages/ui/src/linkify-comments.tsxdeleted file mode 100644index 5e78a10388..0000000000--- a/packages/ui/src/linkify-comments.tsx+++ /dev/null@@ -1,28 +0,0 @@--import * as linkify from "linkifyjs";-//to convert links in comments clickable-export function LinkifyComments({ children }:{children:string}) {-- function renderText(comment: string) {- console.log({comment})- const extractedLinks = linkify.find(comment);- const final = comment.split(/\s+/).flatMap((part, index) => {-- const foundLink = extractedLinks.find((link) => { return link.value === part })- if (foundLink) {- return [<a href={foundLink.href} key={index} target="_blank" rel="noopener noreferrer nofollow" className="hover:underline">{part}</a>, " "];- }- else {- return [part, " "]- }- })- return final-}-- return (- <div>- {renderText(children)}- </div>- );-}-diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 63ca4e5334..5a3db14937 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -154,6 +154,12 @@ importers:js-cookie:specifier: ^3.0.5version: 3.0.5+ linkify-react:+ specifier: ^4.1.3+ version: 4.1.3([email protected])([email protected])+ linkifyjs:+ specifier: ^4.1.3+ version: 4.1.3lucide-react:specifier: ^0.299.0version: 0.299.0([email protected])@@ -12250,6 +12256,16 @@ packages:resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}+ resolution: {integrity: sha512-rhI3zM/fxn5BfRPHfi4r9N7zgac4vOIxub1wHIWXLA5ENTMs+BGaIaFO1D1PhmxgwhIKmJz3H7uCP0Dg5JwSlA==}+ peerDependencies:+ linkifyjs: ^4.0.0+ react: '>= 15.0.0'+ dependencies:+ linkifyjs: 4.1.3+ react: 18.2.0+ dev: false+resolution: {integrity: sha512-auMesunaJ8yfkHvK4gfg1K0SaKX/6Wn9g2Aac/NwX+l5VdmFZzo/hdPGxEOETj+ryRa4/fiOPjeeKURSAJx1sg==}dev: false