/** * 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; /** * Rendered instead of a 404 when the backend could not be reached. A * published page must not 404 over a blip — that deindexes live content — so * this is a 200 holding page on a render the SDK has already made uncacheable. */ Unavailable: React.ComponentType; /** * Rendered at "/" when no home document exists. Unlike the catch-all, "/" * never 404s: it is a single fixed URL rather than an unbounded crawler * surface, and a welcome state is the right answer for a freshly scaffolded * site — including one with no backend configured yet. */ Fallback: React.ComponentType; /** The app's remote-datasource fetcher registry. */ fetchers?: RemoteDatasourceFetcher[]; /** * Turns published page data into metadata. Called only for a page that * actually resolved; the miss and outage titles come from `titles`. * * Defaults to the SDK's own resolver, which maps the stored root props * (`_seo`, `_meta`) onto the head tags using `fetchers` for `{{ }}` * resolution. Pass one to replace that mapping — to add tags on top of it, * call `resolvePageMetadata` with its `transform` option. */ resolveMetadata?: (args: { pageData: Data; path: string; }) => Metadata | Promise; titles?: { /** Catch-all, no such page. Default "Not Found". */ notFound?: string; /** Backend unreachable. Default "Temporarily unavailable". */ unavailable?: string; /** "/" with no home document yet — pairs with `Fallback`. Default "Home". */ home?: string; }; /** Extra internal path prefixes to refuse, on top of the SDK's own list. */ internalPathPrefixes?: readonly string[]; }; export declare function createPublishedPage(config: CreatePublishedPageConfig): { Page: ({ params }: { params: Promise<{ puckPath?: string[]; }>; }) => Promise; getDocumentLanguage: ({ params, }: { params: Promise<{ puckPath?: string[]; }>; }) => Promise; HomePage: () => Promise; generateMetadata: ({ params }: { params: Promise<{ puckPath?: string[]; }>; }) => Promise; generateHomeMetadata: () => Promise; generateStaticParams: () => { puckPath: string[]; }[]; };