mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-11 09:51:40 +00:00
* feat: refactor registry * fix: remove components * refactor: getActiveStyle * fix: prettier in build-registry Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix * Update apps/v4/scripts/build-registry.mts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix * Update apps/v4/scripts/build-registry.mts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update apps/v4/components/block-viewer.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
106 lines
2.1 KiB
TypeScript
106 lines
2.1 KiB
TypeScript
import { Metadata } from "next"
|
|
import { notFound } from "next/navigation"
|
|
|
|
import { siteConfig } from "@/lib/config"
|
|
import { getRegistryComponent, getRegistryItems } from "@/lib/registry"
|
|
import { absoluteUrl, cn } from "@/lib/utils"
|
|
import { getStyle, STYLES } from "@/registry/styles"
|
|
|
|
export const revalidate = false
|
|
export const dynamic = "force-static"
|
|
export const dynamicParams = false
|
|
|
|
const allowedTypes = ["registry:example"]
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{
|
|
style: string
|
|
}>
|
|
}): Promise<Metadata> {
|
|
const { style: styleName } = await params
|
|
const style = getStyle(styleName)
|
|
|
|
if (!style) {
|
|
return {}
|
|
}
|
|
|
|
const title = style.title
|
|
|
|
return {
|
|
title,
|
|
openGraph: {
|
|
title,
|
|
type: "article",
|
|
url: absoluteUrl(`/sandbox/${style.name}`),
|
|
images: [
|
|
{
|
|
url: siteConfig.ogImage,
|
|
width: 1200,
|
|
height: 630,
|
|
alt: siteConfig.name,
|
|
},
|
|
],
|
|
},
|
|
twitter: {
|
|
card: "summary_large_image",
|
|
title,
|
|
images: [siteConfig.ogImage],
|
|
creator: "@shadcn",
|
|
},
|
|
}
|
|
}
|
|
|
|
export async function generateStaticParams() {
|
|
return STYLES.map((style) => ({
|
|
style: style.name,
|
|
}))
|
|
}
|
|
|
|
export default async function BlockPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{
|
|
style: string
|
|
}>
|
|
}) {
|
|
const { style: styleName } = await params
|
|
const style = getStyle(styleName)
|
|
|
|
if (!style) {
|
|
return notFound()
|
|
}
|
|
|
|
const items = await getRegistryItems(style.name, (item) =>
|
|
allowedTypes.includes(item.type)
|
|
)
|
|
|
|
if (items.length === 0) {
|
|
return notFound()
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className={cn("grid gap-6")}>
|
|
{items
|
|
.filter((item) => item !== null)
|
|
.map((item) => {
|
|
const Component = getRegistryComponent(item.name, style.name)
|
|
if (!Component) {
|
|
return null
|
|
}
|
|
return (
|
|
<div
|
|
key={item.name}
|
|
className={cn("bg-background", item.meta?.container)}
|
|
>
|
|
<Component />
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
</>
|
|
)
|
|
}
|