/** * Route builders for the published-page render pipeline. * * The pipeline itself — read the page, branch on the outcome, resolve route * templates and remote datasources, render — is the same for every P1 site, and * carries the invariants documented in published-page.ts. Hand-assembling it in * each app's route files froze a copy of it into every scaffold, so improvements * to caching or datasource resolution could never reach a project once it was * created. It lives here instead, and the routes become shims. * * What genuinely differs per app flows in as options: the render client (which * holds that app's puck.config), the components shown when content is * unavailable or the home page has no document yet, the app's datasource * fetcher registry, and how it turns page data into
metadata. * * Usage: * // app/published-pages.tsx (shared module — one instance, both routes) * import { createPublishedPage } from "@pantheon-systems/p1-next-sdk/server"; * export const published = createPublishedPage({ ... }); * * // app/[[...puckPath]]/page.tsx — "/" and every other page * export const revalidate = 300; * export default published.Page; * export const generateMetadata = published.generateMetadata; * export const generateStaticParams = published.generateStaticParams; * * // app/[[...puckPath]]/layout.tsx — the root layout * const lang = (await published.getDocumentLanguage({ params })) ?? "en"; * * `HomePage` and `generateHomeMetadata` serve a separate `app/page.tsx` for an * app whose catch-all is `[...puckPath]` rather than optional. * * `revalidate` must stay a literal in the route file. Next.js statically * analyzes segment-config exports, so re-exporting one through the factory * leaves it undetected and the route silently loses its revalidation window — * the same constraint that keeps `dynamic` in the route file for createP1Pages. */ import type { Metadata } from "next"; import { type RemoteDatasourceFetcher } from "@pantheon-systems/puck-css/server"; import type { Data } from "@puckeditor/core"; import { type PublishedPageLocalization } from "./localization-react"; /** * Describes the rendered document to the render client, which uses it for the * edit affordances that only make sense once a real document is on screen. */ export type PublishedPageMetadata = { route: string; documentName?: string; pageType?: "page" | "template" | "override"; }; export type PublishedPageClientProps = { data: Data; pageMetadata: PublishedPageMetadata; /** * The page's locale and its locale variants. Present only on a site with * locales. The same value is available to any component below the client * through `useP1Localization`. */ localization?: PublishedPageLocalization; }; export type CreatePublishedPageConfig = { /** * Renders resolved Puck data. Holds the app's puck.config, which is why this * cannot live in the SDK. */ Client: React.ComponentType