The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add a blog
Steven Tey578270dc54c2
diff --git a/app/dub.sh/blog/[slug]/page.tsx b/app/dub.sh/blog/[slug]/page.tsxnew file mode 100644index 0000000000..fd306e7754--- /dev/null+++ b/app/dub.sh/blog/[slug]/page.tsx@@ -0,0 +1,109 @@+import SearchButton from "#/ui/content/search-button";+import MaxWidthWrapper from "@/components/shared/max-width-wrapper";+import { allBlogPosts } from "contentlayer/generated";+import { notFound } from "next/navigation";+import Link from "next/link";+import Author from "#/ui/content/author";+import { MDX } from "#/ui/content/mdx";+import TableOfContents from "#/ui/content/table-of-contents";+import Feedback from "#/ui/content/feedback";+import { getBlurDataURL } from "#/lib/images";+import { Metadata } from "next";+import { constructMetadata } from "#/lib/utils";+import { getTweet } from "react-tweet/api";+import BlurImage from "#/ui/blur-image";++export async function generateStaticParams() {+ return allBlogPosts.map((post) => ({+ slug: post.slug,+ }));+}++export async function generateMetadata({+ params,+}: {+ params: { slug: string };+}): Promise<Metadata | undefined> {+ const post = allBlogPosts.find((post) => post.slug === params.slug);+ if (!post) {+ return;+ }++ const { title, summary, image } = post;++ return constructMetadata({+ title: `${title} | Dub Help Center`,+ description: summary,+ image,+ });+}++export default async function BlogArticle({+ params,+}: {+ params: {+ slug: string;+ };+}) {+ const data = allBlogPosts.find((post) => post.slug === params.slug);+ if (!data) {+ notFound();+ }++ const [thumbnailBlurhash, images, tweets] = await Promise.all([+ getBlurDataURL(data.image),+ await Promise.all(+ data.images.map(async (src: string) => ({+ src,+ blurDataURL: await getBlurDataURL(src),+ })),+ ),+ await Promise.all(data.tweetIds.map(async (id: string) => getTweet(id))),+ ]);++ const relatedArticles =+ (data.related &&+ data.related.map(+ (slug) => allBlogPosts.find((post) => post.slug === slug)!,+ )) ||+ [];++ return (+ <>+ <MaxWidthWrapper>+ <div className="flex max-w-screen-sm flex-col space-y-4 pt-10">+ <h1 className="font-display text-3xl font-extrabold text-gray-700 sm:text-4xl">+ {data.title}+ </h1>+ <p className="text-xl text-gray-500">{data.summary}</p>+ </div>+ </MaxWidthWrapper>++ <div className="relative">+ <div className="absolute top-28 h-full w-full border border-gray-200 bg-white/50 shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.2)] backdrop-blur-lg" />+ <MaxWidthWrapper className="grid grid-cols-4 gap-10 py-10">+ <div className="relative col-span-4 mb-10 flex flex-col space-y-8 rounded-xl border border-gray-200 bg-white sm:col-span-3">+ <BlurImage+ className="rounded-t-xl"+ src={data.image}+ blurDataURL={thumbnailBlurhash}+ width={1200}+ height={630}+ alt={data.title}+ priority // cause it's above the fold+ />+ <MDX+ code={data.body.code}+ images={images}+ tweets={tweets}+ className="px-6 pb-20 pt-4"+ />+ </div>+ <div className="sticky top-20 col-span-1 hidden flex-col space-y-10 divide-y divide-gray-200 self-start sm:flex">+ <Author username={data.author} />+ </div>+ </MaxWidthWrapper>+ </div>+ </>+ );+}diff --git a/content/blog/introducing-dub.mdx b/content/blog/introducing-dub.mdxnew file mode 100644index 0000000000..00538214a4--- /dev/null+++ b/content/blog/introducing-dub.mdx@@ -0,0 +1,39 @@+---+title: Introducing Dub+publishedAt: 2022-09-22+summary: Meet Dub – an open-source link-shortener SaaS with built-in analytics + free custom domains.+image: https://d2vwwcvoksz7ty.cloudfront.net/blog/thumbnail.png+author: steventey+categories:+ - company+---++Introducing Dub – an open-source link-shortener SaaS with built-in analytics + free custom domains.++Some context: Since joining [Vercel](https://vercel.com/), I've had the chance to work with some of the coolest tech on the web.++E.g.: with [Edge Functions](https://vercel.com/features/edge-functions), you can now run server-side logic like redirects at close proximity to users – which is perfect for a tool like Dub.++To visualize how Edge Functions work, I created a 3D globe on our homepage that shows the locations of the last 30 clicks on [dub.sh/github](http://dub.sh/github) in real-time 👇++## Analytics that matter++On top of fast redirects, a link shortener SaaS also needs data visualization to help marketing teams understand the performance of their links.++With [Airbnb's Visx library](http://airbnb.io/visx), I built a dashboard to visualize the time-series data for each link's clicks (incl. location, device/os).++## Use your own custom domain for free++Another cool feature of Dub: free custom domains on all plans.++You can use your own domain for your links (e.g. [stey.me](http://stey.me/)) – even on the free plan.++## Fully open-source and self-hostable++I'm excited to announce that this project is fully open-source, released under the AGPLv3 license 🥳++This means you can clone, modify, and even deploy your own instance of Dub, as long as you open-source it.++Here's a link to the GitHub repository: [dub.sh/github](https://dub.sh/github)++<Tweet id="1572958186667233282" />diff --git a/contentlayer.config.ts b/contentlayer.config.tsindex 69401dfe3a..5a2cda5560 100644--- a/contentlayer.config.ts+++ b/contentlayer.config.ts@@ -6,6 +6,51 @@ import rehypeAutolinkHeadings from "rehype-autolink-headings";import GithubSlugger from "github-slugger";import { capitalize } from "./lib/utils";+export const BlogPost = defineDocumentType(() => ({+ name: "BlogPost",+ filePathPattern: `**/blog/*.mdx`,+ contentType: "mdx",+ fields: {+ title: {+ type: "string",+ required: true,+ },+ publishedAt: {+ type: "date",+ required: true,+ },+ summary: {+ type: "string",+ required: true,+ },+ image: {+ type: "string",+ required: true,+ },+ author: {+ type: "string",+ required: true,+ },+ categories: {+ type: "list",+ of: {+ type: "enum",+ options: ["company", "education", "customer-stories"],+ default: "company",+ },+ required: true,+ },+ related: {+ type: "list",+ of: {+ type: "string",+ },+ },+ },+ // @ts-ignore+ computedFields: computedFields("blog"),+}));+export const ChangelogPost = defineDocumentType(() => ({name: "ChangelogPost",filePathPattern: `**/changelog/*.mdx`,@@ -101,7 +146,7 @@ export const LegalPost = defineDocumentType(() => ({computedFields: computedFields("legal"),}));-const computedFields = (type: "changelog" | "help" | "legal") => ({+const computedFields = (type: "blog" | "changelog" | "help" | "legal") => ({slug: {type: "string",resolve: (doc) => doc._raw.flattenedPath.replace(`${type}/`, ""),@@ -168,7 +213,7 @@ const computedFields = (type: "changelog" | "help" | "legal") => ({export default makeSource({contentDirPath: "content",- documentTypes: [ChangelogPost, LegalPost, HelpPost],+ documentTypes: [BlogPost, ChangelogPost, LegalPost, HelpPost],mdx: {remarkPlugins: [remarkGfm],rehypePlugins: [diff --git a/lib/constants/index.ts b/lib/constants/index.tsindex ec9625974b..263fadf79e 100644--- a/lib/constants/index.ts+++ b/lib/constants/index.ts@@ -94,6 +94,7 @@ export const SHOW_BACKGROUND_SEGMENTS = new Set(["metatags","pricing","help",+ "blog","login","register",]);