The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improved link favicon previews
Steven Teybea2256b906a
diff --git a/components/app/link-card.tsx b/components/app/link-card.tsxindex 0a368eecb9..fd3ab1f461 100644--- a/components/app/link-card.tsx+++ b/components/app/link-card.tsx@@ -52,9 +52,9 @@ export default function LinkCard({ props }: { props: LinkProps }) {<li className="flex flex-col sm:flex-row justify-between items-start sm:items-center space-y-5 sm:space-y-0 bg-white p-4 rounded-lg shadow hover:shadow-md transition-all"><div className="relative flex items-center space-x-4"><BlurImage- src={`https://logo.clearbit.com/${urlHostname}`}+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${urlHostname}`}alt={urlHostname}- className="w-10 h-10 rounded-full border border-gray-200"+ className="w-10 h-10 rounded-full"width={20}height={20}/>diff --git a/components/app/modals/add-edit-link-modal.tsx b/components/app/modals/add-edit-link-modal.tsxindex 33f57eb694..f0ba31bf20 100644--- a/components/app/modals/add-edit-link-modal.tsx+++ b/components/app/modals/add-edit-link-modal.tsx@@ -57,7 +57,8 @@ function AddEditLinkModal({if (props?.url) {const urlHostname = new URL(props.url).hostname;return {- avatar: `https://logo.clearbit.com/${urlHostname}`,+ avatar: `https://www.google.com/s2/favicons?sz=64&domain_url=${urlHostname}`,+ alt: urlHostname,copy: `Edit ${linkConstructor({key: props.key,domain,@@ -67,6 +68,7 @@ function AddEditLinkModal({} else {return {avatar: "/static/logo.png",+ alt: "Dub.sh",copy: "Add a new link",};}@@ -149,8 +151,8 @@ function AddEditLinkModal({<div className="flex flex-col justify-center items-center space-y-3 sm:px-16 px-4 pt-8 py-4 border-b border-gray-200"><BlurImagesrc={heroProps.avatar}- alt={heroProps.copy}- className="w-10 h-10 rounded-full border border-gray-200"+ alt={heroProps.alt}+ className="w-10 h-10 rounded-full"width={20}height={20}/>@@ -184,127 +186,131 @@ function AddEditLinkModal({setKeyExistsError(true);});}}- className="flex flex-col space-y-6 text-left bg-gray-50 sm:px-16 px-4 py-8"+ className="grid gap-6 bg-gray-50 py-8">- <div>- <div className="flex justify-between items-center">- <label- htmlFor="key"- className="block text-sm font-medium text-gray-700"- >- Short Link- </label>- <button- className="hover:text-black active:scale-95 flex items-center space-x-2 text-gray-500 text-sm transition-all duration-75"- onClick={generateRandomSlug}- disabled={generatingSlug}- type="button"- >- {generatingSlug && <LoadingCircle />}- <p>{generatingSlug ? "Generating" : "Generate random slug"}</p>- </button>- </div>- <div className="relative flex mt-1 rounded-md shadow-sm">- <span className="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-5 text-gray-500 sm:text-sm whitespace-nowrap">- {domain || "dub.sh"}- </span>- <input- type="text"- name="key"- id="key"- required- autoFocus={false}- pattern="[\p{Letter}\p{Mark}\d-]+" // Unicode regex to match characters from all languages and numbers (and omit all symbols except for dashes)- className={`${- keyExistsError- ? "border-red-300 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"- : "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"- } pr-10 block w-full rounded-r-md focus:outline-none sm:text-sm`}- placeholder="github"- value={key}- onChange={(e) => {- setKeyExistsError(false);- setData({ ...data, key: e.target.value });- }}- aria-invalid="true"- aria-describedby="key-error"- />+ <div className="grid gap-6 sm:px-16 px-4">+ <div>+ <div className="flex justify-between items-center">+ <label+ htmlFor="key"+ className="block text-sm font-medium text-gray-700"+ >+ Short Link+ </label>+ <button+ className="hover:text-black active:scale-95 flex items-center space-x-2 text-gray-500 text-sm transition-all duration-75"+ onClick={generateRandomSlug}+ disabled={generatingSlug}+ type="button"+ >+ {generatingSlug && <LoadingCircle />}+ <p>+ {generatingSlug ? "Generating" : "Generate random slug"}+ </p>+ </button>+ </div>+ <div className="relative flex mt-1 rounded-md shadow-sm">+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-5 text-gray-500 sm:text-sm whitespace-nowrap">+ {domain || "dub.sh"}+ </span>+ <input+ type="text"+ name="key"+ id="key"+ required+ autoFocus={false}+ pattern="[\p{Letter}\p{Mark}\d-]+" // Unicode regex to match characters from all languages and numbers (and omit all symbols except for dashes)+ className={`${+ keyExistsError+ ? "border-red-300 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ : "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"+ } pr-10 block w-full rounded-r-md focus:outline-none sm:text-sm`}+ placeholder="github"+ value={key}+ onChange={(e) => {+ setKeyExistsError(false);+ setData({ ...data, key: e.target.value });+ }}+ aria-invalid="true"+ aria-describedby="key-error"+ />+ {keyExistsError && (+ <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">+ <AlertCircleFill+ className="h-5 w-5 text-red-500"+ aria-hidden="true"+ />+ </div>+ )}+ </div>{keyExistsError && (- <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">- <AlertCircleFill- className="h-5 w-5 text-red-500"- aria-hidden="true"- />- </div>+ <p className="mt-2 text-sm text-red-600" id="key-error">+ Short link is already in use.+ </p>)}</div>- {keyExistsError && (- <p className="mt-2 text-sm text-red-600" id="key-error">- Short link is already in use.- </p>- )}- </div>- <div>- <label- htmlFor="url"- className="block text-sm font-medium text-gray-700"- >- Destination URL- </label>- <div className="flex mt-1 rounded-md shadow-sm">- <input- name="url"- id="url"- type="url"- required- className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 block w-full rounded-md focus:outline-none sm:text-sm"- placeholder="https://github.com/steven-tey/dub"- value={url}- onChange={(e) => {- setData({ ...data, url: e.target.value });- }}- aria-invalid="true"- />- </div>- </div>-- <div>- <div className="flex justify-between items-center">+ <div><label- htmlFor="title"+ htmlFor="url"className="block text-sm font-medium text-gray-700">- Title+ Destination URL</label>- <button- className={`${- url.length === 0- ? "cursor-not-allowed text-gray-300"- : "hover:text-black active:scale-95"- } flex items-center space-x-2 text-gray-500 text-sm transition-all duration-75`}- onClick={() => generateTitleFromUrl(url)}- disabled={url.length === 0 || generatingTitle}- type="button"- >- {generatingTitle && <LoadingCircle />}- <p>{generatingTitle ? "Generating" : "Generate from URL"}</p>- </button>+ <div className="flex mt-1 rounded-md shadow-sm">+ <input+ name="url"+ id="url"+ type="url"+ required+ className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 block w-full rounded-md focus:outline-none sm:text-sm"+ placeholder="https://github.com/steven-tey/dub"+ value={url}+ onChange={(e) => {+ setData({ ...data, url: e.target.value });+ }}+ aria-invalid="true"+ />+ </div></div>- <div className="flex mt-1 rounded-md shadow-sm">- <TextareaAutosize- name="title"- id="title"- required- minRows={3}- className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 pr-10 block w-full rounded-md focus:outline-none sm:text-sm"- placeholder="Dub - an open-source link shortener SaaS with built-in analytics + free custom domains."- value={title}- onChange={(e) => {- setData({ ...data, title: e.target.value });- }}- aria-invalid="true"- />++ <div>+ <div className="flex justify-between items-center">+ <label+ htmlFor="title"+ className="block text-sm font-medium text-gray-700"+ >+ Title+ </label>+ <button+ className={`${+ url.length === 0+ ? "cursor-not-allowed text-gray-300"+ : "hover:text-black active:scale-95"+ } flex items-center space-x-2 text-gray-500 text-sm transition-all duration-75`}+ onClick={() => generateTitleFromUrl(url)}+ disabled={url.length === 0 || generatingTitle}+ type="button"+ >+ {generatingTitle && <LoadingCircle />}+ <p>{generatingTitle ? "Generating" : "Generate from URL"}</p>+ </button>+ </div>+ <div className="flex mt-1 rounded-md shadow-sm">+ <TextareaAutosize+ name="title"+ id="title"+ required+ minRows={3}+ className="border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500 pr-10 block w-full rounded-md focus:outline-none sm:text-sm"+ placeholder="Dub - an open-source link shortener SaaS with built-in analytics + free custom domains."+ value={title}+ onChange={(e) => {+ setData({ ...data, title: e.target.value });+ }}+ aria-invalid="true"+ />+ </div></div></div>@@ -316,20 +322,22 @@ function AddEditLinkModal({/>)}- <button- disabled={saving || keyExistsError}- className={`${- saving || keyExistsError- ? "cursor-not-allowed bg-gray-100 border-gray-200 text-gray-400"- : "bg-black hover:bg-white hover:text-black border-black text-white"- } flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}- >- {saving ? (- <LoadingDots color="#808080" />- ) : (- <p>{props ? "Save changes" : "Add link"}</p>- )}- </button>+ <div className="sm:px-16 px-4">+ <button+ disabled={saving || keyExistsError}+ className={`${+ saving || keyExistsError+ ? "cursor-not-allowed bg-gray-100 border-gray-200 text-gray-400"+ : "bg-black hover:bg-white hover:text-black border-black text-white"+ } flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}+ >+ {saving ? (+ <LoadingDots color="#808080" />+ ) : (+ <p>{props ? "Save changes" : "Add link"}</p>+ )}+ </button>+ </div></form></div></Modal>@@ -377,21 +385,23 @@ function AdvancedSettings({ data, setData, debouncedUrl }) {return (<div>- <button- type="button"- className="flex items-center"- onClick={() => setExpanded(!expanded)}- >- <ChevronRight- className={`h-5 w-5 text-gray-600 ${- expanded ? "rotate-90" : ""- } transition-all`}- />- <p className="text-gray-600 text-sm">Advanced options</p>- </button>+ <div className="sm:px-16 px-4">+ <button+ type="button"+ className="flex items-center"+ onClick={() => setExpanded(!expanded)}+ >+ <ChevronRight+ className={`h-5 w-5 text-gray-600 ${+ expanded ? "rotate-90" : ""+ } transition-all`}+ />+ <p className="text-gray-600 text-sm">Advanced options</p>+ </button>+ </div>{expanded && (- <div className="mt-4 grid gap-5">+ <div className="mt-4 grid gap-5 bg-white border-t border-b border-gray-200 sm:px-16 px-4 py-8"><div><div className="flex justify-between items-center"><labeldiff --git a/components/app/modals/delete-link-modal.tsx b/components/app/modals/delete-link-modal.tsxindex 58d8902805..5aaedb9eb4 100644--- a/components/app/modals/delete-link-modal.tsx+++ b/components/app/modals/delete-link-modal.tsx@@ -46,7 +46,7 @@ function DeleteLinkModal({<div className="inline-block w-full sm:max-w-md overflow-hidden align-middle transition-all transform bg-white sm:border sm:border-gray-200 shadow-xl sm:rounded-2xl"><div className="flex flex-col justify-center items-center space-y-3 sm:px-16 px-4 pt-8 py-4 border-b border-gray-200"><BlurImage- src={`https://logo.clearbit.com/${urlHostname}`}+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${urlHostname}`}alt={urlHostname}className="w-10 h-10 rounded-full border border-gray-200"width={20}diff --git a/components/app/modals/delete-project-modal.tsx b/components/app/modals/delete-project-modal.tsxindex aa43a34f30..64138a5e71 100644--- a/components/app/modals/delete-project-modal.tsx+++ b/components/app/modals/delete-project-modal.tsx@@ -33,7 +33,7 @@ function DeleteProjectModal({<div className="inline-block w-full sm:max-w-md overflow-hidden align-middle transition-all transform bg-white sm:border sm:border-gray-200 shadow-xl sm:rounded-2xl"><div className="flex flex-col justify-center items-center space-y-3 sm:px-16 px-4 pt-8 py-4 border-b border-gray-200"><BlurImage- src={`https://logo.clearbit.com/${domain}`}+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${domain}`}alt={domain}className="w-10 h-10 rounded-full border border-gray-200"width={20}diff --git a/components/app/modals/edit-domain-modal.tsx b/components/app/modals/edit-domain-modal.tsxindex b55a860d3b..1ddf741f3d 100644--- a/components/app/modals/edit-domain-modal.tsx+++ b/components/app/modals/edit-domain-modal.tsx@@ -52,7 +52,7 @@ function EditDomainModal({<div className="inline-block w-full sm:max-w-md overflow-hidden align-middle transition-all transform bg-white sm:border sm:border-gray-200 shadow-xl sm:rounded-2xl"><div className="flex flex-col justify-center items-center space-y-3 sm:px-16 px-4 pt-8 py-4 border-b border-gray-200"><BlurImage- src={`https://logo.clearbit.com/${domain}`}+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${domain}`}alt={domain}className="w-10 h-10 rounded-full border border-gray-200"width={20}diff --git a/components/app/modals/link-qr-modal.tsx b/components/app/modals/link-qr-modal.tsxindex e02b44f74c..9eaa221d1a 100644--- a/components/app/modals/link-qr-modal.tsx+++ b/components/app/modals/link-qr-modal.tsx@@ -29,10 +29,13 @@ function LinkQRModalHelper({}) {const anchorRef = useRef<HTMLAnchorElement>();const { project: { domain, logo } = {} } = useProject();- const avatarUrl = useMemo(() => {+ const { avatarUrl, urlHostname } = useMemo(() => {try {const urlHostname = new URL(props.url).hostname;- return `https://logo.clearbit.com/${urlHostname}`;+ return {+ avatarUrl: `https://www.google.com/s2/favicons?sz=64&domain_url=${urlHostname}`,+ urlHostname,+ };} catch (e) {return null;}@@ -81,7 +84,7 @@ function LinkQRModalHelper({{avatarUrl ? (<BlurImagesrc={avatarUrl}- alt="Download QR Code"+ alt={urlHostname}className="w-10 h-10 rounded-full border border-gray-200"width={40}height={40}diff --git a/components/home/link-card.tsx b/components/home/link-card.tsxindex b8eba0a7e7..cc6290db99 100644--- a/components/home/link-card.tsx+++ b/components/home/link-card.tsx@@ -116,12 +116,12 @@ export default function LinkCard({onDrag={() => setVelocity(x.getVelocity())}onDragEnd={() => flyAway(500)}whileTap={{ scale: 1.05 }}- className="cursor-grab active:cursor-grabbing flex items-center border border-gray-200 hover:border-black bg-white p-3 max-w-md rounded-md transition-[border-color]"+ className="cursor-grab active:cursor-grabbing flex items-center space-x-3 border border-gray-200 hover:border-black bg-white p-3 max-w-md rounded-md transition-[border-color]"><BlurImage- src={`https://logo.clearbit.com/${urlHostname}`}+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${urlHostname}`}alt={urlHostname}- className="w-10 h-10 rounded-full mr-2 border border-gray-200 pointer-events-none"+ className="w-10 h-10 rounded-full pointer-events-none"width={20}height={20}/>diff --git a/next.config.js b/next.config.jsindex aef436df70..80639293a0 100644--- a/next.config.js+++ b/next.config.js@@ -3,7 +3,7 @@ module.exports = {reactStrictMode: true,images: {domains: [- "logo.clearbit.com",+ "www.google.com","avatar.tobi.sh","faisalman.github.io","avatars.dicebear.com",diff --git a/pages/proxy/[domain]/[key].tsx b/pages/proxy/[domain]/[key].tsxindex 445d3421c6..eea7ad2bd8 100644--- a/pages/proxy/[domain]/[key].tsx+++ b/pages/proxy/[domain]/[key].tsx@@ -5,20 +5,25 @@ import prisma from "@/lib/prisma";import { LinkProps } from "@/lib/types";import { redis } from "@/lib/upstash";-export default function LinkPage({ url, title, description, image, logo }) {+export default function LinkPage({ hostname, title, description, image }) {return (<><Head><meta property="og:title" content={escape(title)} />- <meta property="og:site_name" content={escape(url)} />+ <meta property="og:site_name" content={escape(hostname)} /><meta property="og:description" content={escape(description)} /><meta property="og:image" content={escape(image)} /><meta name="twitter:card" content="summary_large_image" />- <meta name="twitter:site" content={escape(url)} />+ <meta name="twitter:site" content={escape(hostname)} /><meta name="twitter:title" content={escape(title)} /><meta name="twitter:description" content={escape(description)} /><meta name="twitter:image" content={escape(image)} />- {logo && <link rel="icon" href={logo} />}+ <link+ rel="icon"+ href={`https://www.google.com/s2/favicons?sz=64&domain_url=${escape(+ hostname,+ )}`}+ /></Head><main className="w-screen h-screen flex items-center justify-center"><div className="w-full max-w-lg mx-5 sm:mx-0 border border-gray-200 rounded-lg overflow-hidden">@@ -30,15 +35,15 @@ export default function LinkPage({ url, title, description, image, logo }) {className="w-full object-cover"/><div className="flex space-x-3 bg-gray-100 p-5">- {logo && (- <Image- src={logo}- alt={title}- width={300}- height={300}- className="w-6 h-6 mt-1"- />- )}+ <Image+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${escape(+ hostname,+ )}`}+ alt={title}+ width={300}+ height={300}+ className="w-6 h-6 mt-1"+ /><div className="flex flex-col space-y-3"><h1 className="text-gray-700 font-bold">{title}</h1><p className="text-gray-500 text-sm">{description}</p>@@ -70,24 +75,15 @@ export async function getStaticProps(ctx) {revalidate: 1,};}- const project = await prisma.project.findUnique({- where: {- domain,- },- select: {- logo: true,- },- });const hostname = new URL(url).hostname;return {props: {- url: hostname,+ hostname,title,description,image,- logo: project?.logo,},revalidate: 300,};