The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added linkifyjs for links
aakash2330ecb376315dd3
diff --git a/apps/web/yarn-error.log b/apps/web/yarn-error.lognew file mode 100644index 0000000000..7510a0b79d--- /dev/null+++ b/apps/web/yarn-error.log@@ -0,0 +1,152 @@+Arguments:+ /usr/local/bin/node /snap/node/7823/bin/yarn.js config get registry++PATH:+ /home/necromancer/code/os/forkedDub/dub/apps/web/node_modules/.bin:/home/necromancer/code/os/forkedDub/dub/apps/node_modules/.bin:/home/necromancer/code/os/forkedDub/dub/node_modules/.bin:/home/necromancer/code/os/forkedDub/node_modules/.bin:/home/necromancer/code/os/node_modules/.bin:/home/necromancer/code/node_modules/.bin:/home/necromancer/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/opt/jdk-13.0.1/bin:/home/necromancer/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/necromancer/.fzf/bin++Yarn version:+ 1.22.19++Node version:+ 18.17.0++Platform:+ linux x64++Trace:+ Error: EACCES: permission denied, write+ at writeSync (node:fs:936:3)+ at SyncWriteStream._write (node:internal/fs/sync_write_stream:26:3)+ at writeOrBuffer (node:internal/streams/writable:392:12)+ at _write (node:internal/streams/writable:333:10)+ at Writable.write (node:internal/streams/writable:337:10)+ at Object.clearLine (node:internal/readline/callbacks:107:17)+ at clearLine (/snap/node/7823/lib/cli.js:49463:12)+ at ConsoleReporter._log (/snap/node/7823/lib/cli.js:92832:43)+ at ConsoleReporter.log (/snap/node/7823/lib/cli.js:92821:10)+ at get (/snap/node/7823/lib/cli.js:83506:14)++npm manifest:+ {+ "name": "web",+ "private": true,+ "license": "AGPL-3.0-or-later",+ "scripts": {+ "dev": "concurrently --kill-others \"prisma generate && next dev --port 8888\" \"prisma studio --browser none\"",+ "build": "prisma generate & next build",+ "format:write": "prettier --write \"**/*.{css,js,json,jsx,ts,tsx}\"",+ "format": "prettier \"**/*.{css,js,json,jsx,ts,tsx}\"",+ "lint": "next lint",+ "start": "next start",+ "script": "tsx ./scripts/run.ts"+ },+ "dependencies": {+ "@boxyhq/saml-jackson": "^1.14.2",+ "@dub/tailwind-config": "workspace:*",+ "@dub/ui": "workspace:*",+ "@dub/utils": "workspace:*",+ "@next-auth/prisma-adapter": "^1.0.5",+ "@planetscale/database": "^1.7.0",+ "@prisma/client": "^5.2.0",+ "@react-email/components": "^0.0.7",+ "@sindresorhus/slugify": "^2.2.1",+ "@splinetool/react-spline": "^2.2.6",+ "@splinetool/runtime": "^0.9.481",+ "@stripe/stripe-js": "^1.44.1",+ "@upstash/qstash": "^0.3.6",+ "@upstash/ratelimit": "^0.3.6",+ "@upstash/redis": "^1.25.1",+ "@vercel/analytics": "^1.0.0",+ "@vercel/edge": "^0.3.1",+ "@vercel/edge-config": "^0.4.1",+ "@vercel/og": "^0.0.21",+ "@vercel/speed-insights": "^1.0.1",+ "@visx/axis": "^2.14.0",+ "@visx/event": "^2.6.0",+ "@visx/geo": "^2.10.0",+ "@visx/grid": "^2.12.2",+ "@visx/responsive": "^2.10.0",+ "@visx/scale": "^3.3.0",+ "@visx/shape": "^2.12.2",+ "@visx/tooltip": "^2.16.0",+ "bottleneck": "^2.19.5",+ "cloudinary": "^1.40.0",+ "cmdk": "^0.2.0",+ "cobe": "^0.6.3",+ "concurrently": "^8.0.1",+ "crisp-sdk-web": "^1.0.19",+ "framer-motion": "^10.12.12",+ "fuse.js": "^6.6.2",+ "github-slugger": "^2.0.0",+ "he": "^1.2.0",+ "html-escaper": "^3.0.3",+ "js-cookie": "^3.0.5",+ "lucide-react": "^0.269.0",+ "nanoid": "^5.0.1",+ "next": "14.0.4-canary.39",+ "next-auth": "^4.24.4",+ "node-html-parser": "^6.1.4",+ "nodemailer": "^6.9.3",+ "npm": "^9.1.2",+ "openapi-types": "^12.1.3",+ "prisma": "^5.2.0",+ "punycode": "^2.3.0",+ "react": "^18.2.0",+ "react-colorful": "^5.6.1",+ "react-dom": "^18.2.0",+ "react-dom-confetti": "^0.2.0",+ "react-email": "^1.9.5",+ "react-highlight-words": "^0.20.0",+ "react-medium-image-zoom": "^5.1.7",+ "react-parallax-tilt": "^1.7.70",+ "react-spring": "^9.5.5",+ "react-textarea-autosize": "^8.4.0",+ "react-tweet": "^3.1.1",+ "rehype-autolink-headings": "^6.1.1",+ "rehype-pretty-code": "^0.9.5",+ "rehype-slug": "^5.1.0",+ "remark-gfm": "^3.0.1",+ "resend": "1.1.0",+ "shiki": "^0.14.1",+ "sonner": "^0.5.0",+ "stripe": "^12.12.0",+ "swr": "^2.1.5",+ "topojson-client": "^3.1.0",+ "unsplash-js": "^7.0.18",+ "use-debounce": "^8.0.4",+ "vaul": "^0.6.8"+ },+ "devDependencies": {+ "@trivago/prettier-plugin-sort-imports": "^4.0.0",+ "@types/dotenv-flow": "^3.3.2",+ "@types/he": "^1.2.3",+ "@types/html-escaper": "^3.0.0",+ "@types/ms": "^0.7.31",+ "@types/node": "18.11.9",+ "@types/react": "^18.2.14",+ "@types/react-dom": "^18.2.14",+ "@types/react-highlight-words": "^0.16.4",+ "@types/topojson-client": "^3.1.1",+ "array-to-ndjson": "^1.0.1",+ "autoprefixer": "^10.4.16",+ "dotenv-flow": "^4.0.0",+ "papaparse": "^5.4.1",+ "postcss": "^8.4.31",+ "postcss-import": "^15.1.0",+ "prettier": "^2.8.0",+ "prettier-plugin-tailwindcss": "^0.1.13",+ "tailwindcss": "^3.3.3",+ "tsx": "^3.14.0",+ "turbo": "^1.10.14",+ "typescript": "^5.1.6"+ },+ "browser": {+ "crypto": false+ }+ }++yarn manifest:+ No manifest++Lockfile:+ No lockfilediff --git a/packages/ui/package.json b/packages/ui/package.jsonindex ff42d8efd4..062a5e8224 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -43,6 +43,7 @@"@radix-ui/react-tooltip": "^1.0.7","class-variance-authority": "^0.7.0","js-cookie": "^3.0.5",+ "linkifyjs": "^4.1.3","lucide-react": "^0.284.0","sonner": "^0.5.0","swr": "^2.1.5",diff --git a/packages/ui/src/linkify-comments.tsx b/packages/ui/src/linkify-comments.tsxindex 29e1a57c31..5e78a10388 100644--- a/packages/ui/src/linkify-comments.tsx+++ b/packages/ui/src/linkify-comments.tsx@@ -1,22 +1,27 @@+import * as linkify from "linkifyjs";//to convert links in comments clickableexport function LinkifyComments({ children }:{children:string}) {- const urlPattern = /(\bhttps?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;- const renderText = (text:string) => {- const parts = text.split(urlPattern);- return parts.map((part, index) => {- if (part.match(urlPattern)) {- return <a href={part} key={index} target="_blank" rel="noopener noreferrer nofollow" className="hover:underline">{part}</a>;- } else {- return part;- }- });- };+ 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)}+ {renderText(children)}</div>);}