The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
construct metadata manually
Steven Tey05d8ecdabd02
diff --git a/app/dub.sh/changelog/page.tsx b/app/dub.sh/changelog/page.tsxindex 79a7cd9a1f..e1ec10692e 100644--- a/app/dub.sh/changelog/page.tsx+++ b/app/dub.sh/changelog/page.tsx@@ -2,37 +2,18 @@ import BlurImage from "#/ui/blur-image";import { getBlurDataURL } from "@/lib/images";import { allChangelogPosts } from "contentlayer/generated";import { Metadata } from "next";-import { formatDate } from "@/lib/utils";+import { constructMetadata, formatDate } from "@/lib/utils";import Link from "next/link";import { MDX } from "#/ui/blog/mdx";import { Twitter } from "@/components/shared/icons";import { Rss } from "lucide-react";-const title = "Changelog - Dub";-const description =- "All the latest updates, improvements, and fixes to Dub - the link management tool for modern marketing teams.";-const image = "https://dub.sh/api/og/changelog";--export const metadata: Metadata = {- title,- description,- openGraph: {- title,- description,- images: [- {- url: image,- },- ],- },- twitter: {- title,- description,- images: [image],- },- metadataBase: new URL("https://dub.sh"),- themeColor: "#FFF",-};+export const metadata = constructMetadata({+ title: "Changelog - Dub",+ description:+ "All the latest updates, improvements, and fixes to Dub - the link management tool for modern marketing teams.",+ image: "https://dub.sh/api/og/changelog",+});export default async function Changelog() {return (diff --git a/app/dub.sh/metatags/page.tsx b/app/dub.sh/metatags/page.tsxindex 990e5e2d42..3f72640d3a 100644--- a/app/dub.sh/metatags/page.tsx+++ b/app/dub.sh/metatags/page.tsx@@ -3,23 +3,13 @@ import { Suspense } from "react";import Background from "@/components/shared/background";import LaunchTweet from "./launch";import MetatagsContent from "./content";+import { constructMetadata } from "@/lib/utils";-const title = "Metatags API - The Free API to Get Meta Tags from a URL";-const description =- "Dub's Metatags API is a free & simple API to retrieve meta & OG tags from a URL, powered by Vercel Edge Functions.";--export const metadata = {- title,- description,- openGraph: {- title,- description,- },- twitter: {- title,- description,- },-};+export const metadata = constructMetadata({+ title: "Metatags API - The Free API to Get Meta Tags from a URL",+ description:+ "Dub's Metatags API is a free & simple API to retrieve meta & OG tags from a URL, powered by Vercel Edge Functions.",+});export default function Metatags() {return (diff --git a/app/dub.sh/stats/[key]/page.tsx b/app/dub.sh/stats/[key]/page.tsxindex efb5edfffd..68a34a18c1 100644--- a/app/dub.sh/stats/[key]/page.tsx+++ b/app/dub.sh/stats/[key]/page.tsx@@ -2,6 +2,8 @@ import { notFound } from "next/navigation";import { getLinkViaEdge } from "@/lib/planetscale";import Stats from "#/ui/stats";import { Suspense } from "react";+import { Metadata } from "next";+import { constructMetadata } from "@/lib/utils";export const runtime = "edge";@@ -9,29 +11,18 @@ export async function generateMetadata({params,}: {params: { key: string };-}) {+}): Promise<Metadata | undefined> {const data = await getLinkViaEdge("dub.sh", params.key);if (!data || !data.publicStats) {return;}- const title = `Stats for dub.sh/${params.key} - Dub`;- const description = `Stats page for dub.sh/${params.key}, which redirects to ${data.url}.`;- const image = `https://dub.sh/api/og/stats?domain=dub.sh&key=${params.key}`;-- return {- title,- description,- image,- twitter: {- card: "summary_large_image",- title,- description,- image,- creator: "@dubdotsh",- },- };+ return constructMetadata({+ title: `Stats for dub.sh/${params.key} - Dub`,+ description: `Stats page for dub.sh/${params.key}, which redirects to ${data.url}.`,+ image: `https://dub.sh/api/og/stats?domain=dub.sh&key=${params.key}`,+ });}export async function generateStaticParams() {diff --git a/app/layout.tsx b/app/layout.tsxindex c2aae0343c..ed06eefa92 100644--- a/app/layout.tsx+++ b/app/layout.tsx@@ -3,35 +3,9 @@ import { satoshi, inter } from "@/styles/fonts";import { Analytics } from "@vercel/analytics/react";import clsx from "clsx";import { Providers } from "./providers";-import { Metadata } from "next";+import { constructMetadata } from "@/lib/utils";-const title = "Dub - Link Management for Modern Marketing Teams";-const description =- "Dub is an open-source link management tool for modern marketing teams to create, share, and track short links.";-const image = "https://dub.sh/_static/thumbnail.png";--export const metadata: Metadata = {- title,- description,- openGraph: {- title,- description,- images: [- {- url: image,- },- ],- },- twitter: {- card: "summary_large_image",- title,- description,- images: [image],- creator: "@dubdotsh",- },- metadataBase: new URL("https://dub.sh"),- themeColor: "#FFF",-};+export const metadata = constructMetadata({});export default function RootLayout({children,diff --git a/app/ui/blog/mdx.tsx b/app/ui/blog/mdx.tsxindex a1de5c77d2..8fa7f9fbda 100644--- a/app/ui/blog/mdx.tsx+++ b/app/ui/blog/mdx.tsx@@ -47,6 +47,7 @@ export function MDX({ code, images, tweets, repos }: MDXProps) {return (<BlurImage{...props}+ alt={props.alt || "Image"}placeholder="blur"blurDataURL={blurDataURL ||diff --git a/app/ui/stats/locations.tsx b/app/ui/stats/locations.tsxindex f23910815e..9d040260c4 100644--- a/app/ui/stats/locations.tsx+++ b/app/ui/stats/locations.tsx@@ -49,6 +49,7 @@ export default function Locations() {<div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center"><span className="z-10 flex items-center space-x-2 px-2"><img+ alt={country}src={`https://flag.vercel.app/m/${country}.svg`}className="h-3 w-5"/>diff --git a/components/stats/locations.tsx b/components/stats/locations.tsxindex ddf52ee799..fe100ff747 100644--- a/components/stats/locations.tsx+++ b/components/stats/locations.tsx@@ -51,6 +51,7 @@ export default function Locations() {<div className="relative z-10 flex w-full max-w-[calc(100%-3rem)] items-center"><span className="z-10 flex items-center space-x-2 px-2"><img+ alt={country}src={`https://flag.vercel.app/m/${country}.svg`}className="h-3 w-5"/>diff --git a/lib/qr/index.tsx b/lib/qr/index.tsxindex 48f9ddff18..7789cef699 100644--- a/lib/qr/index.tsx+++ b/lib/qr/index.tsx@@ -284,6 +284,7 @@ export function QRCodeCanvas(props: QRPropsCanvas) {if (imgSrc != null) {img = (<img+ alt="QR code"src={imgSrc}key={imgSrc}style={{ display: "none" }}diff --git a/lib/utils.ts b/lib/utils.tsindex 8ab492a1f0..3567c1f5bd 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -1,3 +1,4 @@+import { Metadata } from "next";import { NextRouter } from "next/router";import ms from "ms";import { customAlphabet } from "nanoid";@@ -9,6 +10,39 @@ import {} from "./constants";import { get } from "@vercel/edge-config";+export function constructMetadata({+ title = "Dub - Link Management for Modern Marketing Teams",+ description = "Dub is an open-source link management tool for modern marketing teams to create, share, and track short links.",+ image = "https://dub.sh/_static/thumbnail.png",+}: {+ title?: string;+ description?: string;+ image?: string;+}): Metadata {+ return {+ title,+ description,+ openGraph: {+ title,+ description,+ images: [+ {+ url: image,+ },+ ],+ },+ twitter: {+ card: "summary_large_image",+ title,+ description,+ images: [image],+ creator: "@dubdotsh",+ },+ metadataBase: new URL("https://dub.sh"),+ themeColor: "#FFF",+ };+}+export const nanoid = customAlphabet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7,