The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
tweaks
Steven Tey1506e469f621
diff --git a/apps/web/emails/clicks-summary.tsx b/apps/web/emails/clicks-summary.tsxindex 78e77d13c8..0a05cd60d9 100644--- a/apps/web/emails/clicks-summary.tsx+++ b/apps/web/emails/clicks-summary.tsx@@ -28,7 +28,7 @@ export default function ClicksSummary({createdLinks = 25,topLinks = [{- link: "acmesuperlongdomain.com/instagram",+ link: "acmesuperlongdomain.com/insta",clicks: 1820,},{@@ -135,7 +135,7 @@ export default function ClicksSummary({href={`https://app.dub.co/${workspaceSlug}/analytics?domain=${domain}&key=${path}`}className="text-sm font-medium text-black underline">- {smartTruncate(link, 36)}↗+ {smartTruncate(link, 33)}↗</Link></Column><Columndiff --git a/packages/utils/src/functions/smart-truncate.ts b/packages/utils/src/functions/smart-truncate.tsindex 6d790b0212..e5815c2a00 100644--- a/packages/utils/src/functions/smart-truncate.ts+++ b/packages/utils/src/functions/smart-truncate.ts@@ -6,48 +6,35 @@import { truncate } from "./truncate";-// Function to truncate domain while preserving TLD and 2 characters before the dot+// Function to truncate domain while preserving TLDconst truncateDomain = (domain: string, maxLength: number): string => {const parts = domain.split(".");const tld = parts.pop() || "";const rest = parts.join(".");- const minRestLength = 3;- if (rest.length + tld.length + 1 <= maxLength) {- return `${rest}.${tld}`;- }-- if (maxLength <= minRestLength + tld.length + 1) {- return `${rest.slice(0, minRestLength)}.${tld}`;- }-- const truncatedRest = truncate(rest, maxLength - tld.length - 1)!;- return `${truncatedRest}${rest.slice(-2)}.${tld}`;+ return `${rest.slice(0, maxLength)}...${tld}`;};-export const smartTruncate = (link: string, length: number): string => {- if (link.length <= length) {+export const smartTruncate = (link: string, maxLength: number): string => {+ if (link.length <= maxLength) {return link;}const [domain, ...pathParts] = link.split("/");const path = pathParts.join("/");- const minDomainLength = 12;+ const minDomainLength = 8;- // Calculate maximum domain length- const maxDomainLength = Math.max(- minDomainLength,- Math.floor(length / 2), // Allow up to half of total length for domain- );-- // Truncate domain if necessary, preserving TLD- const truncatedDomain = truncateDomain(domain, maxDomainLength);-- // Calculate remaining length for path- const remainingLength = Math.max(0, length - truncatedDomain.length - 1);+ // calculate max path length+ const maxPathLength = maxLength - minDomainLength;// Truncate path- const truncatedPath = truncate(path, remainingLength);+ const truncatedPath = truncate(path, maxPathLength)!;++ // Truncate domain if necessary, preserving TLD+ const truncatedDomain = truncateDomain(+ domain,+ maxLength - truncatedPath.length,+ );return `${truncatedDomain}/${truncatedPath}`;};