Files
ipal-kit/docs/frontend.md
T
Radosław SmolińskiandClaude Opus 5.5 21ef0fdeb0 1.18.0 (owner's decisions Q3, Q4, Q5): writes that keep others' saves, access answers announced, drafts out of related documents
- Q3: the integration status (emailStatus, turnstileStatus) is written alone through the
  database adapter (writeGlobalFields, exported): a visitor's form submit no longer puts back an
  admin's SMTP or Turnstile change saved at the same moment. addToCookieList reads the list again
  right before writing and works the change out again when an editor's save changed it (up to 5
  times). Both races reproduced exactly in test/statusWrites.test.ts, on the three adapters.
- Q4: cookieScanner.access and the doctor's access go through accessAllowed: any truthy answer
  still allows, an answer that is not a boolean is reported once per option; strict (only true)
  is announced for 1.19.0.
- Q5: related documents that are drafts are left out of what the public helpers answer
  (resolveRoute, getSettings, getArchiveEntries, the 404 page, llms-full; Markdown and MCP through
  resolveRoute): null alone, removed from a list, value null in a polymorphic one. A preview keeps
  them; draftRelations: 'keep' keeps the old behaviour. withoutDraftRelations,
  applyDraftRelations exported.
- Docs: content.md, frontend.md, integrations.md, cookie-scanner.md, security.md, AGENT.md;
  iapl-nav and iapl-doctor skills.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 11:15:13 +01:00

186 lines
14 KiB
Markdown

# frontend — `createContentHelpers`, `createPageRoute`, `SiteProviders`
The layer the project wires into `app/`: one helper factory (`src/lib/content.ts`),
a ready catch-all page and a component with the layout providers. All optional —
each piece has a lower-level equivalent (content.md, seo.md, links.md).
## `createContentHelpers` → `src/lib/content.ts`
```ts
// src/lib/content.ts
import { createContentHelpers } from '@intecion/ipal-kit'
import config from '@payload-config'
import { contentConfig } from '@/content.config'
import { i18nConfig } from '@/i18n.config'
export const {
getCachedPayload, getSettings, resolveRoute, getEntries, generateStaticParams,
generatePageMetadata, getSiteShell, sitemap, robots, /* … */
} = createContentHelpers({ config, content: contentConfig, i18n: i18nConfig })
```
All reads are wrapped in React `cache()`; the Payload instance is created once in the factory
and shared by the helpers (generateMetadata and the page share queries).
### Options
| Option | Default | What it does |
|---|---|---|
| `config` | — (required) | Payload config (promise or object) |
| `content` | — | the same `ContentOption` as in the plugin (content.md) |
| `i18n` | — | `I18nConfig`; **without it these throw**: `generatePageMetadata`, `getPageJsonLd`, `sitemap`, `getLinkOptions`/`resolveLink`/`resolveNav`/`getSystemLinks`, `resolvePageRedirect`, `getConstructionMode`, `getSiteShell`, `llmsRoute`, `llmsFullRoute`, `mcpGET`/`mcpPOST`, `manifest` |
| `baseUrl` | `NEXT_PUBLIC_SERVER_URL`, then `''` | origin for sitemap/robots/canonical/JSON-LD |
| `pagesSlug` | `'pages'` | pages collection |
| `settingsSlug` | `'site-settings'` | SiteSettings global |
| `redirectCollections` | `[{ slug: 'pages' }]` | collections checked by `resolvePageRedirect` (slug history) |
| `markdown` | — | `{ frontmatter, layoutField, overrides, isPathVisible }` for `markdownRoute` (`isPathVisible` defaults to the helper below; `() => true` = no construction filter) |
| `markdownAlternate` | off | `true`/prefix → `generatePageMetadata` adds `<link rel="alternate" type="text/markdown">` (indexable pages) |
| `mcp` | — | `{ serverName, serverVersion, rateLimit, maxBatch, clientIp, isPathVisible }` for `mcpGET`/`mcpPOST` (mcp.md) |
| `pageJsonLd` | — | default `getPageJsonLd` options: `breadcrumbs`, `entryType`, `entries`, `faq`, `pageType` |
| `robots` | — | `RobotsOptions` for `robots` and `getRobots` (seo.md); `aiBotRules: [{ userAgent, access }]` = per-bot exceptions from code (the panel's rules come after them) |
| `draftRelations` | `'hide'` | related documents that are drafts are left out of what the helpers answer (1.18.0); `'keep'` as before (content.md "Drafts as related documents") |
| `settingsDepth` | `1` | depth of `getSettings`: Site settings relations arrive as documents, theirs as ids (the archive page is read separately at depth 2); `2` = every request pays for more |
| `siteJsonLd` | WebSite + Organization from Site settings | a function replaces it, `false` = none |
| `sitemapEntries` | — | `(entries) => entries` — final sitemap list: add URLs of your own routes, remove some, set `priority` |
| `sitemapImages` | the document's SEO image | `(doc) => url[]` |
| `sitemapOptions` | `{ maxUrls: 10000, cacheControl: 'public, max-age=0, s-maxage=3600, stale-while-revalidate=86400', memoSeconds: 300 }` | `sitemapRoute`: above `maxUrls` it serves a `<sitemapindex>` with `?part=N` parts (`Infinity` = never split); `cacheControl: false` = no header; `memoSeconds: 0` = no in-process memo |
| `sitemapStyle` | built-in style | `false` = raw XML |
| `summaryField` | — | field from `buildSummaryField` for llms.txt / MCP |
| `underConstructionSeo` | `true` | under construction the sitemap and llms.txt list only the open pages; `false` = list everything |
### Returned keys (what `@/lib/content` exports)
| Key | Signature / usage |
|---|---|
| `getCachedPayload` | `() => Promise<Payload>` |
| `getConfiguredLocales` | `() => Promise<string[]>` (from `config.localization`) |
| `getSettings` | `(locale)` — SiteSettings, `depth: 1` (`settingsDepth`), one read per language per request |
| `resolveRoute` | `(locale, segments, page)` → `ResolvedRoute \| null` (content.md) |
| `getEntries` | `(collection, locale, page, perPage)` → `ArchiveEntries` |
| `getNotFoundPage` | `(locale)` — 404 page from System pages or `null`, does not throw (pages.md) |
| `generatePageMetadata` | `(locale, segments, page = 1)` → `Metadata` for `generateMetadata` |
| `getPageJsonLd` | `(locale, segments, options?)` → nodes for `<JsonLdGraph>` (WebPage / BlogPosting / CollectionPage, BreadcrumbList, FAQPage); `[]` for noindex |
| `generateStaticParams` | see below |
| `sitemap` | `app/sitemap.ts`: `export { sitemap as default }` (does not split; a database error throws at runtime, `[]` only during `next build`) |
| `sitemapRoute` | `app/sitemap.xml/route.ts`: `export { sitemapRoute as GET }` |
| `robots` | `app/robots.ts`: `export { robots as default }` — rules from code only (sync) |
| `getRobots` | `app/robots.ts`: `export { getRobots as default }` + `export const dynamic = 'force-dynamic'` — `robots` plus the AI crawler policy and per-bot rules from Site settings → Search engines, read per request; database unreachable → the code options |
| `manifest` | `app/manifest.ts`: `export { manifest as default }` |
| `llmsRoute`, `llmsFullRoute` | `app/llms.txt/route.ts`, `app/llms-full.txt/route.ts` (seo.md) |
| `markdownRoute` | `app/md/[locale]/[[...slug]]/route.ts` (content.md) |
| `mcpGET`, `mcpPOST` | `app/api/mcp/route.ts` (mcp.md) |
| `healthRoute` | `app/api/health/route.ts` |
| `indexNowKeyRoute` | IndexNow key file route (seo.md) |
| `getHomeSlug` | `(locale)` — home page slug |
| `getLinkOptions` | `(locale)` — options for `resolveLinkHref` / `RenderForm linkOptions` (with `content` archives) |
| `resolveLink`, `resolveNav`, `getSystemLinks` | links.md |
| `resolvePageRedirect` | `(locale, segments)` → new path from slug history or `null` |
| `getConstructionMode` | `(locale)` — under-construction mode state (construction.md) |
| `isPathVisible` | `(path, locale)` → `Promise<boolean>` — `false` for a page construction mode hides (path as a visitor sees it, `/pl/o-nas`); already wired into `markdownRoute` and `mcpPOST`, pass it to `createSearchRoute({ …, isPathVisible })`; concurrent calls share one mode read per locale |
| `getFormTexts` | `(locale)` — form texts from Notifications |
| `getSiteShell` | `(locale)` → `SiteShell` for the layout (consent, analytics, turnstile, jsonLd, settings, theme, formTexts) |
| `i18n` | the `I18nConfig` passed in |
### `generateStaticParams` — what it really generates
The docstring of `generateStaticParams` in `createContentHelpers.ts` talks about content collections, but the code
queries **only the `pagesSlug` collection**, `limit: 1000` per language, no pagination:
- home page → `slug: []` (root); the page assigned as 404 and the slugs `404`/`500`/`error`/`not-found` are skipped,
- drafts filtered out in memory, `noindex` pages **stay** (they must render),
- one language → `{ slug }[]`, several → `{ locale, slug }[]`,
- **`content` collection entries and archive pages > 1 are not generated**, nor more than 1000 pages per language — they render on request,
- database unreachable during the build → `[]` + a warning.
Entries as SSG: your own `generateStaticParams` that merges the helper's result with `buildEntryPath`/a query for entries.
## `createPageRoute` — catch-all page (`/rsc`)
```tsx
// app/(frontend)/[locale]/[[...slug]]/page.tsx
import { notFound, permanentRedirect, redirect } from 'next/navigation'
import { createPageRoute } from '@intecion/ipal-kit/rsc'
import * as content from '@/lib/content'
import { blockRegistry } from '@/blocks/registry'
export const revalidate = 3600 // literal in the file
const route = createPageRoute(content, { blocks: blockRegistry, notFound, permanentRedirect, redirect })
export default route.Page
export const generateMetadata = route.generateMetadata
export const generateStaticParams = route.generateStaticParams
```
Order in `Page`: under-construction mode (when `redirect` is passed) → `resolveRoute(locale, segments, 1)` →
no route: `resolvePageRedirect` (308) or `onMissing` → home page slug at its own address: 308 to root
(`homeAlias`) → `RenderBlocks` with `{ locale, isFirst, firstImage, …blockProps }` → `render` (optional) → `<JsonLdGraph>`.
`isFirst` / `firstImage` come from `blockPosition({ allBlocks, index })` (root): the first section (its heading is the
page's `h1`) and "no block before this one shows an image" (its first image is the LCP image; `blockHasImage(data)`
checks a block's data). Your own `enhanceProps` can spread `blockPosition(args)` the same way.
| Option | Default | What it does |
|---|---|---|
| `blocks` | — (required) | `blockType → component` registry |
| `notFound`, `permanentRedirect` | — (required) | from `next/navigation` (injected) |
| `redirect` | — | from `next/navigation`; turns on under-construction mode and `onMissing: 'redirectHome'` |
| `onMissing` | `'notFound'` | `'redirectHome'` (307 to the home page) or a function `({ locale, segments }) => …` |
| `homeAlias` | `'redirect'` | `false` = the home page also renders at its own slug |
| `blockProps` | — | `({ doc, locale }) => props` for every block |
| `render` | — | `({ route, blocks, locale, segments }) => ReactNode \| undefined` — your own archive/entry view |
| `jsonLd` | `true` | `false` or `getPageJsonLd` options |
| `layoutField` | `'layout'` | field with the blocks |
**Limitation:** always page 1 — `?page=` is not read (archive pagination: content.md).
No `[locale]` in params → `i18n.defaultLocale` (single-language site).
404: `createNotFoundPage` / `renderNotFoundView` — pages.md.
## `SiteProviders` — layout (`/rsc`)
```tsx
// app/(frontend)/[locale]/layout.tsx
import { SiteProviders } from '@intecion/ipal-kit/rsc'
import { getSiteShell } from '@/lib/content'
<body>
<SiteProviders shell={await getSiteShell(locale)}>
<Header /><main>{children}</main><Footer />
</SiteProviders>
</body>
```
Renders: `<ThemeScript>` (when `theme`), `<MediaPreconnect>`, `<JsonLdGraph>` (site JSON-LD + `jsonLd`),
`<ConsentProvider>` with `<TurnstileProvider>` (and `<LightboxProvider>` when `lightbox`), `<CookieBanner>`, `<CookieButton>`, `<Analytics>`, `<PageStats>`.
It does not mount `AlternateLinksProvider` (i18n.md) — add it yourself if you use `LanguageSwitcher`.
| Prop | Default | What it does |
|---|---|---|
| `shell` | — (required) | result of `getSiteShell(locale)` |
| `logEndpoint` | `shell.consentLogEndpoint` | consent log endpoint (on by default since 1.17.0); `false` = decisions not posted |
| `gpc` | `'honour'` | Global Privacy Control: `'honour'`, `'ask'`, `false` (consent.md) |
| `maxAgeDays` | `180` | days a choice is kept before the banner asks again |
| `banner` | `<CookieBanner />` | your own banner or `false` |
| `cookieButton` | `<CookieButton />` | your own button or `false` |
| `consentCookie` | — | optional server read of the consent cookie (`(await cookies()).get(CONSENT_COOKIE)?.value ?? null`): exact HTML, but the pages become dynamic. Left out (default): pages stay static and the banner decides before the first paint with an inline script — consent.md → "First paint" |
| `analytics` | on | extra `<Analytics>` props or `false` = no tags |
| `cookieMap` | — | extra cookies per category to clean up after consent is withdrawn |
| `jsonLd` | `[]` | extra JSON-LD nodes |
| `lightbox` | off | `true` / `{ texts, classNames, icons, loop, unstyled }` → one `<LightboxProvider>` for the site; texts from `shell.lightboxTexts` (Form messages → Image viewer) — lightbox.md |
| `nonce` | — | CSP nonce (`(await headers()).get('x-nonce')` with `createProxy({ csp })`) for the theme script, the cookie banner's first-paint script and the analytics tags — security.md |
| `preconnect` | `true` | `<link rel=preconnect>` to the media origin |
| `stats` | off | `true`/props → `<PageStats>` (stats.md) |
| `theme` | `false` | `<ThemeScript>` before the first paint (theme.md) |
## Turn off, override, extend
- All three are optional — the project can build the page and layout from lower-level pieces
(`resolveRoute`, `getArchiveEntries`, `createPageMetadata`, `RenderBlocks`, `ConsentProvider`…).
- Any key from `createContentHelpers` can be left out of the destructuring or replaced with your own function
of the same name in `src/lib/content.ts` (e.g. your own `generateStaticParams` with entries).
- `createPageRoute`: your own view through `render`, your own 404/redirect through `onMissing`, extra block props through `blockProps`, JSON-LD through `jsonLd`.
- `SiteProviders`: `lightbox` is off by default; for `renderImage` / `renderDialog` (functions) mount `<LightboxProvider>` yourself in a client component instead (lightbox.md).
- The cookie banner is in the server HTML and painted with the page (1.17.0; it used to appear after hydration and could be the LCP element). Off: `banner={<CookieBanner firstPaint={false} />}`; server-exact HTML on a dynamic site: `consentCookie` (consent.md → "First paint").
- `SiteProviders`: `banner`, `cookieButton`, `analytics` accept your own element or `false`; `analytics={{ consentMode: 'basic' }}` = no request to Google before consent (default `'advanced'`: the tag loads with every signal `denied`).
- Search engines from the panel: `robots` instead of `getRobots` ignores it; your own robots: `buildRobots({ ...robotsOptionsFrom(settings), … })`; drop the verification tags: `const { verification, ...meta } = await generatePageMetadata(…)`.
- Construction filter in Markdown / MCP: `markdown: { isPathVisible: () => true }`, `mcp: { isPathVisible: () => true }`; in the sitemap and llms.txt: `underConstructionSeo: false`.
- `createPageRoute` pagination and the `generateStaticParams` scope currently cannot be changed with an option — only with your own code.