From 059a7bf9bcc7c3b0f10c7fcf76ac7d8e3fd73ffe Mon Sep 17 00:00:00 2001 From: Matthew Volk Date: Mon, 17 Jun 2024 13:15:33 -0500 Subject: [PATCH] feat: render makeswift pages in catch-all route --- app/[locale]/(default)/[...rest]/page.tsx | 29 +++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/app/[locale]/(default)/[...rest]/page.tsx b/app/[locale]/(default)/[...rest]/page.tsx index 71d4050..fc3a3ac 100644 --- a/app/[locale]/(default)/[...rest]/page.tsx +++ b/app/[locale]/(default)/[...rest]/page.tsx @@ -1,5 +1,30 @@ +import { Page as MakeswiftPage } from '@makeswift/runtime/next'; +import { getSiteVersion } from '@makeswift/runtime/next/server'; import { notFound } from 'next/navigation'; -export default function CatchAllPage() { - notFound(); +import { client } from '~/makeswift/client'; + +interface CatchAllParams { + locale: string; + rest: string[]; +} + +export async function generateStaticParams() { + const pages = await client.getPages(); + + return pages.map((page) => ({ + path: page.path.split('/').filter((segment) => segment !== ''), + })); +} + +export default async function Page({ params }: { params: CatchAllParams }) { + const path = `/${params.rest.join('/')}`; + + const snapshot = await client.getPageSnapshot(path, { + siteVersion: getSiteVersion(), + }); + + if (snapshot == null) return notFound(); + + return ; }