The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import { Mdx } from '@/components/mdx-components'
import { DocsPager, getBreadcrumbSegments } from '@/components/pager'
import { SourcePanel } from '@/components/source-panel'
import { DashboardTableOfContents } from '@/components/toc'
import { siteConfig } from '@/config/site'
import { getAllDocs, getDocBySlug, getDocMetaBySlug } from '@/lib/docs'
import { getTableOfContents } from '@/lib/toc'
import { absoluteUrl } from '@/lib/utils'
/* eslint-disable turbo/no-undeclared-env-vars */
import '@/styles/mdx.css'
import { ChevronRight } from 'lucide-react'
import type { Metadata } from 'next'
import Link from 'next/link'
import { notFound } from 'next/navigation'
import Balancer from 'react-wrap-balancer'
import { ScrollArea, Separator } from 'ui'
interface DocPageProps {
params: Promise<{
slug: string[]
}>
}
async function getDocFromParams({ params }: { params: { slug: string[] } }) {
const slug = params.slug?.join('/') || ''
return getDocMetaBySlug(slug)
}
export async function generateMetadata(props: DocPageProps): Promise<Metadata> {
const params = await props.params
const doc = await getDocFromParams({ params })
if (!doc) {
return {}
}
return {
title: doc.title,
description: doc.description,
openGraph: {
title: doc.title,
description: doc.description,
type: 'article',
url: absoluteUrl(doc.slug),
images: [
{
url: siteConfig.ogImage,
width: 1200,
height: 630,
alt: siteConfig.name,
},
],
},
twitter: {
card: 'summary_large_image',
title: doc.title,
description: doc.description,
images: [siteConfig.ogImage],
creator: '@shadcn',
},
}
}
export async function generateStaticParams(): Promise<{ slug: string[] }[]> {
if (process.env.NODE_ENV === 'development') {
return []
}
const allDocs = await getAllDocs()
return allDocs.map((doc) => ({
slug: doc.slugAsParams ? doc.slugAsParams.split('/') : [],
}))
}
export default async function DocPage(props: DocPageProps) {
const params = await props.params
const slug = params.slug?.join('/') || ''
const doc = await getDocBySlug(slug)
if (!doc) {
notFound()
}
const toc = await getTableOfContents(doc.raw)
const breadcrumbSegments = getBreadcrumbSegments(doc)
return (
<div className="relative xl:grid xl:grid-cols-[1fr_160px] gap-4 px-6 py-6 lg:py-8">
<div className="mx-auto w-full min-w-0 max-w-4xl flex-1">
<nav
className="mb-4 flex items-center space-x-1 text-sm text-foreground-lighter"
aria-label="Breadcrumb"
>
{breadcrumbSegments.map((segment, index) => (
<span key={segment.title} className="flex items-center gap-1">
{index > 0 && <ChevronRight className="h-4 w-4 shrink-0 text-foreground-muted" />}
{segment.href ? (
<Link
href={segment.href}
className="overflow-hidden text-ellipsis whitespace-nowrap hover:text-foreground transition-colors"
>
{segment.title}
</Link>
) : (
<span className="overflow-hidden text-ellipsis whitespace-nowrap text-foreground-lighter">
{segment.title}
</span>
)}
</span>
))}
{breadcrumbSegments.length > 0 && (
<ChevronRight className="h-4 w-4 shrink-0 text-foreground-muted/50" />
)}
<span className="overflow-hidden text-ellipsis whitespace-nowrap text-foreground-muted">
{doc.title}
</span>
</nav>
<div className="space-y-2 mb-5">
<h1 className="scroll-m-20 text-4xl tracking-tight">{doc.title}</h1>
{doc.description && (
<p className="text-lg text-foreground-light">
<Balancer>{doc.description}</Balancer>
</p>
)}
</div>
<Separator className="mb-6" />
<SourcePanel doc={doc} />
<div className="pb-12">
<Mdx code={doc.code} />
</div>
<DocsPager doc={doc} />
</div>
{doc.toc && (
<div className="hidden text-sm xl:block">
<div className="sticky top-8 -mt-10 pt-8">
<ScrollArea className="pb-10">
<div className="h-[calc(100vh-3.5rem)] py-14">
<DashboardTableOfContents toc={toc} />
</div>
</ScrollArea>
</div>
</div>
)}
</div>
)
}