|
1 | 1 | import { notFound } from "next/navigation" |
2 | 2 | import { CmsBlockRenderer } from "@/components/cms/CmsRenderer" |
3 | | -import { readCmsPages, getActiveTenant } from "@/lib/cms" |
| 3 | +import { readCmsPageVariants } from "@/lib/cms" |
| 4 | +import { parseDemoState, resolvePageBlocks, resolveBlockData } from "@/lib/demo/demo-state" |
4 | 5 |
|
5 | | -interface TenantSlugPageProps { |
6 | | - params: Promise<{ tenant: string; slug: string }> |
| 6 | +interface SlugPageProps { |
| 7 | + params: Promise<{ slug: string }> |
| 8 | + searchParams: Promise<{ theme?: string; layout?: string; text?: string }> |
7 | 9 | } |
8 | 10 |
|
9 | | -export default async function TenantSlugPage({ params }: TenantSlugPageProps) { |
10 | | - const { tenant, slug } = await params |
11 | | - const activeTenant = getActiveTenant() |
12 | | - const pages = readCmsPages(activeTenant) |
13 | | - const page = pages.find((p) => p.slug === slug) |
| 11 | +export default async function SlugPage({ params, searchParams }: SlugPageProps) { |
| 12 | + const { slug } = await params |
| 13 | + const sp = await searchParams |
| 14 | + const state = parseDemoState(new URLSearchParams( |
| 15 | + Object.entries(sp).filter(([, v]) => v != null).map(([k, v]) => `${k}=${v}`).join("&") |
| 16 | + )) |
| 17 | + const page = readCmsPageVariants(slug) |
14 | 18 |
|
15 | | - if (!page || page.blocks.length === 0) { |
| 19 | + if (!page || page.variants.length === 0) { |
16 | 20 | notFound() |
17 | 21 | } |
18 | 22 |
|
19 | | - return ( |
20 | | - <> |
21 | | - {page.blocks.map((block, idx) => ( |
22 | | - <CmsBlockRenderer key={`${block.type}-${idx}`} block={block} /> |
23 | | - ))} |
24 | | - </> |
25 | | - ) |
| 23 | + const blocks = resolvePageBlocks(page, state.layout) |
| 24 | + const resolvedBlocks = blocks.map((block, idx) => { |
| 25 | + const resolved = state.text ? resolveBlockData(block, state.text) : block |
| 26 | + return <CmsBlockRenderer key={`${resolved.type}-${idx}`} block={resolved} /> |
| 27 | + }) |
| 28 | + |
| 29 | + return <>{resolvedBlocks}</> |
26 | 30 | } |
0 commit comments