Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

standardized LinkPreview implementation, finalized changes

Steven Tey4b45041c416a
diff --git a/app/dub.co/tools/inspect/content.tsx b/app/dub.co/tools/inspect/content.tsx
deleted file mode 100644
index 5cc254ec5f..0000000000
--- a/app/dub.co/tools/inspect/content.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-"use client";
-
-import { useEffect, useRef, useState } from "react";
-import { LoadingSpinner } from "#/ui/icons";
-import { useRouter } from "next/navigation";
-import { CornerDownLeft, Link2 } from "lucide-react";
-
-export default function LinkInspectorContent() {
- const router = useRouter();
- const [redirecting, setRedirecting] = useState(false);
-
- const formRef = useRef<HTMLFormElement>(null);
- const inputRef = useRef<HTMLInputElement>(null);
- useEffect(() => {
- inputRef.current?.select();
- }, []);
-
- return (
- <>
- <form
- ref={formRef}
- onSubmit={(e) => {
- e.preventDefault();
- setRedirecting(true);
- router.push(e.currentTarget.url.value);
- }}
- >
- <div className="relative flex items-center">
- <Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-gray-400" />
- <input
- name="url"
- type="url"
- ref={inputRef}
- defaultValue="https://dub.sh/github+"
- // match pattern regex for making sure the url starts with https://dub.sh/, has the slug in the middle, and ends with a +
- pattern="https://dub\.sh/[A-Za-z0-9]+\+"
- placeholder="Enter a dub.sh link to inspect (insert a '+' at the end)"
- autoComplete="off"
- required
- className="peer block w-full rounded-md border border-gray-200 bg-white p-2 pl-10 pr-12 shadow-lg focus:border-black focus:outline-none focus:ring-0 sm:text-sm"
- />
- <button
- type="submit"
- disabled={redirecting}
- className={`${
- redirecting
- ? "cursor-not-allowed bg-gray-100"
- : "hover:border-gray-700 hover:text-gray-700 peer-focus:text-gray-700"
- } absolute inset-y-0 right-0 my-1.5 mr-1.5 flex w-10 items-center justify-center rounded border border-gray-200 font-sans text-sm font-medium text-gray-400`}
- >
- {redirecting ? (
- <LoadingSpinner className="h-4 w-4" />
- ) : (
- <CornerDownLeft className="h-4 w-4" />
- )}
- </button>
- </div>
- </form>
- </>
- );
-}
diff --git a/app/dub.co/tools/inspect/launch.tsx b/app/dub.co/tools/inspect/launch.tsx
deleted file mode 100644
index 143e2d90c7..0000000000
--- a/app/dub.co/tools/inspect/launch.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { getAndCacheTweet } from "#/lib/twitter";
-import Tweet from "#/ui/tweet";
-
-export default async function LaunchTweet() {
- const tweet = await getAndCacheTweet("1695798379836796961");
- if (!tweet) return null;
- return (
- <div className="text-left">
- <Tweet data={tweet} />
- </div>
- );
-}
diff --git a/app/dub.co/tools/inspect/page.tsx b/app/dub.co/tools/inspect/page.tsx
deleted file mode 100644
index 5f984d7159..0000000000
--- a/app/dub.co/tools/inspect/page.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import { Github, Twitter } from "@/components/shared/icons";
-import { Suspense } from "react";
-import Background from "#/ui/home/background";
-import LaunchTweet from "./launch";
-import { constructMetadata } from "#/lib/utils";
-import LinkInspectorContent from "./content";
-
-export const metadata = constructMetadata({
- title: "Link Inspector - Inspect a Short Link on Dub to Make Sure It's Safe",
- description:
- "Dub's Link Inspector is a simple tool for inspecting short links on Dub to make sure it's safe to click on. If you think this link is malicious, please report it.",
-});
-
-export default function LinkInspector() {
- return (
- <>
- <div className="z-10 mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-28">
- <a
- href="https://twitter.com/dubdotsh/status/1695798379836796961"
- target="_blank"
- rel="noreferrer"
- className="mx-auto flex max-w-fit items-center justify-center space-x-2 overflow-hidden rounded-full bg-blue-100 px-7 py-2 transition-all hover:bg-blue-200"
- >
- <Twitter className="h-5 w-5 text-[#1d9bf0]" />
- <p className="text-sm font-semibold text-[#1d9bf0]">
- Watch it in action
- </p>
- </a>
-
- <h1 className="font-display text-5xl font-extrabold leading-[1.15] text-black sm:text-6xl sm:leading-[1.15]">
- <span className="bg-gradient-to-r from-amber-500 via-orange-600 to-yellow-500 bg-clip-text text-transparent">
- Link Inspector
- </span>{" "}
- </h1>
- <h2 className="text-lg text-gray-600 sm:text-xl">
- Inspect a short link on Dub to make sure it's safe to click on. If you
- think this link is malicious, please report it.
- </h2>
-
- <LinkInspectorContent />
-
- <a
- href="https://github.com/steven-tey/dub/blob/be8a9f6ccf5aad8a9839cd0c8cc435a2095599e9/app/inspect/%5Bdomain%5D/%5Bkey%5D/page.tsx"
- target="_blank"
- rel="noreferrer"
- className="mx-auto mt-2 flex items-center justify-center space-x-2 text-sm text-gray-500 transition-all hover:text-black"
- >
- <Github className="h-4 w-4" />
- <p>View the source code</p>
- </a>
-
- <Suspense>
- <LaunchTweet />
- </Suspense>
- </div>
- <Background />
- </>
- );
-}
diff --git a/app/dub.co/tools/inspector/form.tsx b/app/dub.co/tools/inspector/form.tsx
new file mode 100644
index 0000000000..42d42d0c28
--- /dev/null
+++ b/app/dub.co/tools/inspector/form.tsx
@@ -0,0 +1,29 @@
+"use client";
+
+import { Link2 } from "lucide-react";
+
+export default function LinkInspectorForm() {
+ return (
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+ window.open(`${e.currentTarget.url.value}+`, "_blank");
+ }}
+ >
+ <div className="relative flex items-center">
+ <Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-gray-400" />
+ <input
+ name="url"
+ type="url"
+ placeholder="https://dub.sh/github"
+ autoComplete="off"
+ required
+ className="peer block w-full rounded-md border-gray-300 pl-10 pr-12 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500"
+ />
+ <button className="absolute inset-y-0 right-0 my-1.5 mr-1.5 flex w-10 items-center justify-center rounded border border-gray-200 font-sans text-sm font-medium text-gray-400 hover:border-gray-700 hover:text-gray-700 peer-focus:text-gray-700">
+ ↗
+ </button>
+ </div>
+ </form>
+ );
+}
diff --git a/app/dub.co/tools/inspector/page.tsx b/app/dub.co/tools/inspector/page.tsx
new file mode 100644
index 0000000000..d20c47c03f
--- /dev/null
+++ b/app/dub.co/tools/inspector/page.tsx
@@ -0,0 +1,63 @@
+import Background from "#/ui/home/background";
+import { constructMetadata } from "#/lib/utils";
+import LinkInspectorForm from "./form";
+import { Photo } from "@/components/shared/icons";
+import LinkPreview from "#/ui/home/link-preview";
+import Link from "next/link";
+import BlurImage from "#/ui/blur-image";
+
+export const metadata = constructMetadata({
+ title: "Link Inspector - Inspect a Short Link on Dub to Make Sure It's Safe",
+ description:
+ "Dub's Link Inspector is a simple tool for inspecting short links on Dub to make sure it's safe to click on. If you think this link is malicious, please report it.",
+});
+
+export default function LinkInspector() {
+ return (
+ <>
+ <div className="mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16">
+ <h1 className="font-display text-5xl font-extrabold leading-[1.15] text-black sm:text-6xl sm:leading-[1.15]">
+ Link Inspector
+ </h1>
+ <h2 className="text-lg text-gray-600 sm:text-xl">
+ Inspect a short link on Dub to make sure it's safe to click on. If you
+ think this link is malicious, please report it.
+ </h2>
+ <LinkInspectorForm />
+ <a
+ href="/changelog/link-inspector"
+ target="_blank"
+ className="relative overflow-hidden rounded-md border border-gray-300 bg-gray-50"
+ >
+ <BlurImage
+ src="https://d2vwwcvoksz7ty.cloudfront.net/changelog/link-inspector.png"
+ alt="Link Inspector OG image"
+ width={1071}
+ height={630}
+ className="h-[250px] w-full border-b border-gray-300 object-cover"
+ />
+
+ <div className="grid gap-1 bg-white p-3 text-left">
+ <p className="text-sm text-[#536471]">dub.co</p>
+ <h3 className="truncate text-sm font-medium text-[#0f1419]">
+ Link Inspector
+ </h3>
+ <p className="line-clamp-2 text-sm text-[#536471]">
+ You can now inspect short links on Dub by adding a '+' to the end
+ of the short link.
+ </p>
+ </div>
+ </a>
+ <a
+ href="/changelog/link-inspector"
+ rel="noreferrer"
+ target="_blank"
+ className="mx-auto mt-2 flex items-center justify-center space-x-2 text-sm text-gray-500 transition-all hover:text-black"
+ >
+ Read the changelog →
+ </a>
+ </div>
+ <Background />
+ </>
+ );
+}
diff --git a/app/dub.co/tools/metatags/content.tsx b/app/dub.co/tools/metatags/content.tsx
index c848a2a096..d1bdf0c2ab 100644
--- a/app/dub.co/tools/metatags/content.tsx
+++ b/app/dub.co/tools/metatags/content.tsx
@@ -1,24 +1,19 @@
"use client";
-import { useEffect, useMemo, useRef, useState } from "react";
+import { useState } from "react";
import { useDebounce } from "use-debounce";
import useSWR from "swr";
-import { Copy, Photo, Tick } from "@/components/shared/icons";
-import { LoadingCircle } from "#/ui/icons";
-import { fetcher, getDomainWithoutWWW, getUrlFromString } from "#/lib/utils";
+import { Copy, Tick } from "@/components/shared/icons";
+import { fetcher, getUrlFromString } from "#/lib/utils";
import { toast } from "sonner";
-import { useRouter, useSearchParams } from "next/navigation";
+import { useSearchParams } from "next/navigation";
export default function MetatagsContent() {
- const router = useRouter();
const searchParams = useSearchParams();
const url = searchParams?.get("url") || "https://github.com/steven-tey/dub";
const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
- const hostname = useMemo(() => {
- return getDomainWithoutWWW(debouncedUrl || "");
- }, [debouncedUrl]);
- const { data, isValidating } = useSWR<{
+ const { data } = useSWR<{
title: string | null;
description: string | null;
image: string | null;
@@ -30,78 +25,8 @@ export default function MetatagsContent() {
const [copied, setCopied] = useState(false);
- const inputRef = useRef<HTMLInputElement>(null);
- useEffect(() => {
- inputRef.current?.select();
- }, []);
-
return (
<>
- <div className="w-full rounded-md shadow-sm">
- <input
- ref={inputRef}
- name="url"
- id="url"
- type="url"
- autoFocus
- className="block w-full rounded-md border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500"
- placeholder="Enter your URL"
- defaultValue={url}
- onChange={(e) =>
- router.replace(
- `/tools/metatags${
- e.target.value.length > 0 ? `?url=${e.target.value}` : ""
- }`,
- )
- }
- aria-invalid="true"
- />
- </div>
-
- <div className="relative overflow-hidden rounded-md border border-gray-300 bg-gray-50">
- {isValidating && (
- <div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300 bg-gray-50">
- <LoadingCircle />
- </div>
- )}
- {image ? (
- <img
- src={image}
- alt="Preview"
- className="h-[250px] w-full border-b border-gray-300 object-cover"
- />
- ) : (
- <div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300">
- <Photo className="h-8 w-8 text-gray-400" />
- <p className="text-sm text-gray-400">
- Enter a link to generate a preview.
- </p>
- </div>
- )}
- <div className="grid gap-1 bg-white p-3 text-left">
- {hostname ? (
- <p className="text-sm text-[#536471]">{hostname}</p>
- ) : (
- <div className="mb-1 h-4 w-24 rounded-md bg-gray-100" />
- )}
- {title ? (
- <h3 className="truncate text-sm font-medium text-[#0f1419]">
- {title}
- </h3>
- ) : (
- <div className="mb-1 h-4 w-full rounded-md bg-gray-100" />
- )}
- {description ? (
- <p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
- ) : (
- <div className="grid gap-2">
- <div className="h-4 w-full rounded-md bg-gray-100" />
- <div className="h-4 w-48 rounded-md bg-gray-100" />
- </div>
- )}
- </div>
- </div>
-
<button
className="hover:bg/black-[0.08] group relative flex cursor-copy items-center space-x-5 rounded-full bg-black/5 py-2.5 pl-5 pr-3 transition-all"
onClick={() => {
diff --git a/app/dub.co/tools/metatags/page.tsx b/app/dub.co/tools/metatags/page.tsx
index 3dbaabce42..6ee82c6e98 100644
--- a/app/dub.co/tools/metatags/page.tsx
+++ b/app/dub.co/tools/metatags/page.tsx
@@ -4,6 +4,7 @@ import Background from "#/ui/home/background";
import LaunchTweet from "./launch";
import MetatagsContent from "./content";
import { constructMetadata } from "#/lib/utils";
+import LinkPreview from "#/ui/home/link-preview";
export const metadata = constructMetadata({
title: "Metatags API - The Free API to Get Meta Tags from a URL",
@@ -14,7 +15,7 @@ export const metadata = constructMetadata({
export default function Metatags() {
return (
<>
- <div className="z-10 mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-28">
+ <div className="mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-28">
<a
href="https://twitter.com/dubdotco/status/1595459224498233347"
target="_blank"
@@ -38,6 +39,7 @@ export default function Metatags() {
and open-source.
</h2>
+ <LinkPreview />
<MetatagsContent />
<a
diff --git a/app/inspect/[domain]/[key]/card.tsx b/app/inspect/[domain]/[key]/card.tsx
new file mode 100644
index 0000000000..f888980643
--- /dev/null
+++ b/app/inspect/[domain]/[key]/card.tsx
@@ -0,0 +1,57 @@
+import { GOOGLE_FAVICON_URL } from "#/lib/constants";
+import { getApexDomain, linkConstructor } from "#/lib/utils";
+import CopyButton from "@/components/shared/copy-button";
+import BlurImage from "#/ui/blur-image";
+import Script from "next/script";
+import ReportButton from "./report";
+
+export default function LinkInspectorCard({
+ domain,
+ _key,
+ url,
+}: {
+ domain: string;
+ _key: string;
+ url: string;
+}) {
+ const key = _key;
+ const apexDomain = getApexDomain(url);
+ return (
+ <>
+ <Script src="https://tally.so/widgets/embed.js" strategy="lazyOnload" />
+ <div className="flex w-full items-center justify-between rounded-md border border-gray-300 bg-white p-3">
+ <div className="flex items-center space-x-3">
+ <BlurImage
+ src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
+ alt={apexDomain}
+ className="pointer-events-none h-10 w-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ <div>
+ <div className="flex items-center space-x-1 sm:space-x-2">
+ <a
+ className="font-semibold text-blue-800"
+ href={linkConstructor({ domain, key })}
+ target="_blank"
+ rel="noreferrer"
+ >
+ {linkConstructor({ domain, key, pretty: true })}
+ </a>
+ <CopyButton url={linkConstructor({ domain, key })} />
+ </div>
+ <a
+ href={url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="line-clamp-1 text-left text-sm text-gray-500 underline-offset-2 transition-all hover:text-gray-800 hover:underline"
+ >
+ {url}
+ </a>
+ </div>
+ </div>
+ <ReportButton link={linkConstructor({ domain, key })} />
+ </div>
+ </>
+ );
+}
diff --git a/app/inspect/[domain]/[key]/page.tsx b/app/inspect/[domain]/[key]/page.tsx
index 071ad540de..2f43d13789 100644
--- a/app/inspect/[domain]/[key]/page.tsx
+++ b/app/inspect/[domain]/[key]/page.tsx
@@ -1,15 +1,13 @@
-import { GOOGLE_FAVICON_URL } from "#/lib/constants";
import { getLinkViaEdge } from "#/lib/planetscale";
-import { constructMetadata, getApexDomain, linkConstructor } from "#/lib/utils";
+import { constructMetadata, getApexDomain } from "#/lib/utils";
import Footer from "#/ui/home/footer";
import Nav from "#/ui/home/nav";
-import CopyButton from "@/components/shared/copy-button";
import { notFound } from "next/navigation";
-import LinkPreview from "./preview";
import Background from "#/ui/home/background";
-import BlurImage from "#/ui/blur-image";
-import Script from "next/script";
-import ReportButton from "./report";
+import LinkInspectorCard from "./card";
+import LinkPreview from "#/ui/home/link-preview";
+import { HOME_DOMAIN } from "#/lib/constants";
+import { ExpandingArrow } from "#/ui/icons";
export const runtime = "edge";
@@ -28,6 +26,10 @@ export async function generateMetadata({
}
return constructMetadata({
+ title:
+ "Link Inspector - Inspect a Short Link on Dub to Make Sure It's Safe",
+ description:
+ "Dub's Link Inspector is a simple tool for inspecting short links on Dub to make sure it's safe to click on. If you think this link is malicious, please report it.",
noIndex: true,
});
}
@@ -47,14 +49,11 @@ export default async function InspectPage({
notFound();
}
- const apexDomain = getApexDomain(data.url);
-
return (
<>
- <Script src="https://tally.so/widgets/embed.js" strategy="lazyOnload" />
<main className="flex min-h-screen flex-col justify-between">
<Nav />
- <div className="z-10 mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16">
+ <div className="mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16">
<h1 className="font-display text-5xl font-extrabold leading-[1.15] text-black sm:text-6xl sm:leading-[1.15]">
Link Inspector
</h1>
@@ -63,41 +62,16 @@ export default async function InspectPage({
you think this link is malicious, please report it.
</h2>
- <div className="flex w-full items-center justify-between rounded-md border border-gray-300 bg-white p-3">
- <div className="flex items-center space-x-3">
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
- alt={apexDomain}
- className="pointer-events-none h-10 w-10 rounded-full"
- width={20}
- height={20}
- />
- <div>
- <div className="flex items-center space-x-1 sm:space-x-2">
- <a
- className="font-semibold text-blue-800"
- href={linkConstructor({ domain, key })}
- target="_blank"
- rel="noreferrer"
- >
- {linkConstructor({ domain, key, pretty: true })}
- </a>
- <CopyButton url={linkConstructor({ domain, key })} />
- </div>
- <a
- href={data.url}
- target="_blank"
- rel="noopener noreferrer"
- className="line-clamp-1 text-left text-sm text-gray-500 underline-offset-2 transition-all hover:text-gray-800 hover:underline"
- >
- {data.url}
- </a>
- </div>
- </div>
- <ReportButton link={linkConstructor({ domain, key })} />
- </div>
-
- <LinkPreview url={data.url} />
+ <LinkInspectorCard domain={domain} _key={key} url={data.url} />
+ <LinkPreview defaultUrl={data.url} />
+ <a
+ href={`${HOME_DOMAIN}/tools/inspector`}
+ rel="noreferrer"
+ target="_blank"
+ className="mx-auto mt-2 flex items-center justify-center space-x-2 text-sm text-gray-500 transition-all hover:text-black"
+ >
+ Inspect another short link →
+ </a>
</div>
<Footer />
<Background />
diff --git a/app/inspect/[domain]/[key]/preview.tsx b/app/inspect/[domain]/[key]/preview.tsx
deleted file mode 100644
index 08462f96b3..0000000000
--- a/app/inspect/[domain]/[key]/preview.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-"use client";
-import { fetcher, getDomainWithoutWWW } from "#/lib/utils";
-import { LoadingCircle } from "#/ui/icons";
-import { ImageOff } from "lucide-react";
-import useSWR from "swr";
-
-export default function LinkPreview({ url }: { url: string }) {
- const { data, isValidating } = useSWR<{
- title: string | null;
- description: string | null;
- image: string | null;
- }>(`/api/edge/metatags?url=${url}`, fetcher, {
- revalidateOnFocus: false,
- });
-
- const { title, description, image } = data || {};
-
- const hostname = getDomainWithoutWWW(url);
-
- return (
- <div className="relative overflow-hidden rounded-md border border-gray-300 bg-gray-50">
- {isValidating && (
- <div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300 bg-gray-50">
- <LoadingCircle />
- </div>
- )}
- {image ? (
- <img
- src={image}
- alt="Preview"
- className="h-[250px] w-full border-b border-gray-300 object-cover"
- />
- ) : (
- <div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300">
- <ImageOff className="h-8 w-8 text-gray-400" />
- <p className="text-sm text-gray-400">No OG image found.</p>
- </div>
- )}
- <div className="grid gap-1 bg-white p-3 text-left">
- <p className="text-sm text-[#536471]">{hostname}</p>
- {title ? (
- <h3 className="truncate text-sm font-medium text-[#0f1419]">
- {title}
- </h3>
- ) : (
- <div className="mb-1 h-4 w-full rounded-md bg-gray-100" />
- )}
- {description ? (
- <p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
- ) : (
- <div className="grid gap-2">
- <div className="h-4 w-full rounded-md bg-gray-100" />
- <div className="h-4 w-48 rounded-md bg-gray-100" />
- </div>
- )}
- </div>
- </div>
- );
-}
diff --git a/app/ui/home/demo.tsx b/app/ui/home/demo.tsx
index 1d564e5940..e033ff02e5 100644
--- a/app/ui/home/demo.tsx
+++ b/app/ui/home/demo.tsx
@@ -83,7 +83,7 @@ export default function Demo() {
placeholder="Shorten your link"
autoComplete="off"
required
- className="peer block w-full rounded-md border border-gray-200 bg-white p-2 pl-10 pr-12 shadow-lg focus:border-black focus:outline-none focus:ring-0 sm:text-sm"
+ className="peer block w-full rounded-md border-gray-200 pl-10 pr-12 text-sm text-gray-900 placeholder-gray-400 shadow-lg focus:border-gray-500 focus:outline-none focus:ring-gray-500"
/>
<button
type="submit"
diff --git a/app/ui/home/footer.tsx b/app/ui/home/footer.tsx
index a1fc5914dd..ed37a0509c 100644
--- a/app/ui/home/footer.tsx
+++ b/app/ui/home/footer.tsx
@@ -19,7 +19,7 @@ const navigation = {
],
tools: [
{ name: "Metatags API", href: "/tools/metatags" },
- { name: "Link Inspector", href: "/tools/inspect" },
+ { name: "Link Inspector", href: "/tools/inspector" },
],
legal: [
{ name: "Privacy", href: "/privacy" },
diff --git a/app/ui/home/hero.tsx b/app/ui/home/hero.tsx
index 4830fbc361..e6e9267dda 100644
--- a/app/ui/home/hero.tsx
+++ b/app/ui/home/hero.tsx
@@ -1,4 +1,4 @@
-import { allBlogPosts, allChangelogPosts } from "contentlayer/generated";
+import { allBlogPosts } from "contentlayer/generated";
import { Github } from "@/components/shared/icons";
import Link from "next/link";
import { ExpandingArrow } from "../icons";
diff --git a/app/ui/home/link-preview.tsx b/app/ui/home/link-preview.tsx
new file mode 100644
index 0000000000..c77934d198
--- /dev/null
+++ b/app/ui/home/link-preview.tsx
@@ -0,0 +1,112 @@
+"use client";
+
+import { useEffect, useMemo, useRef } from "react";
+import { useDebounce } from "use-debounce";
+import useSWR from "swr";
+import { Photo } from "@/components/shared/icons";
+import { LoadingCircle } from "#/ui/icons";
+import { fetcher, getDomainWithoutWWW, getUrlFromString } from "#/lib/utils";
+import { useRouter, useSearchParams } from "next/navigation";
+import { Link2 } from "lucide-react";
+
+export default function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ const url =
+ defaultUrl ||
+ searchParams?.get("url") ||
+ "https://github.com/steven-tey/dub";
+ const [debouncedUrl] = useDebounce(getUrlFromString(url), 500);
+ const hostname = useMemo(() => {
+ return getDomainWithoutWWW(debouncedUrl || "");
+ }, [debouncedUrl]);
+
+ const { data, isValidating } = useSWR<{
+ title: string | null;
+ description: string | null;
+ image: string | null;
+ }>(debouncedUrl && `/api/edge/metatags?url=${debouncedUrl}`, fetcher, {
+ revalidateOnFocus: false,
+ });
+
+ const { title, description, image } = data || {};
+
+ const inputRef = useRef<HTMLInputElement>(null);
+ useEffect(() => {
+ if (!defaultUrl && inputRef.current) {
+ inputRef.current.select();
+ }
+ }, [defaultUrl]);
+
+ return (
+ <>
+ {!defaultUrl && (
+ <div className="relative flex items-center">
+ <Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-gray-400" />
+ <input
+ ref={inputRef}
+ name="url"
+ id="url"
+ type="url"
+ autoFocus
+ className="block w-full rounded-md border-gray-200 pl-10 text-sm text-gray-900 placeholder-gray-400 shadow-lg focus:border-gray-500 focus:outline-none focus:ring-gray-500"
+ placeholder="Enter your URL"
+ defaultValue={url}
+ onChange={(e) =>
+ router.replace(
+ `/tools/metatags${
+ e.target.value.length > 0 ? `?url=${e.target.value}` : ""
+ }`,
+ )
+ }
+ aria-invalid="true"
+ />
+ </div>
+ )}
+
+ <div className="relative overflow-hidden rounded-md border border-gray-300 bg-gray-50">
+ {isValidating && (
+ <div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300 bg-gray-50">
+ <LoadingCircle />
+ </div>
+ )}
+ {image ? (
+ <img
+ src={image}
+ alt="Preview"
+ className="h-[250px] w-full border-b border-gray-300 object-cover"
+ />
+ ) : (
+ <div className="flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300">
+ <Photo className="h-8 w-8 text-gray-400" />
+ <p className="text-sm text-gray-400">
+ Enter a link to generate a preview.
+ </p>
+ </div>
+ )}
+ <div className="grid gap-1 bg-white p-3 text-left">
+ {hostname ? (
+ <p className="text-sm text-[#536471]">{hostname}</p>
+ ) : (
+ <div className="mb-1 h-4 w-24 rounded-md bg-gray-100" />
+ )}
+ {title ? (
+ <h3 className="truncate text-sm font-medium text-[#0f1419]">
+ {title}
+ </h3>
+ ) : (
+ <div className="mb-1 h-4 w-full rounded-md bg-gray-100" />
+ )}
+ {description ? (
+ <p className="line-clamp-2 text-sm text-[#536471]">{description}</p>
+ ) : (
+ <div className="grid gap-2">
+ <div className="h-4 w-full rounded-md bg-gray-100" />
+ <div className="h-4 w-48 rounded-md bg-gray-100" />
+ </div>
+ )}
+ </div>
+ </div>
+ </>
+ );
+}