Files
ipal-kit/docs/frontend.md
T
Radosław SmolińskiandClaude Opus 5.5 2d9f3e15d4 Docs in English (part 1), seeding guide, Coolify deployment
- Translate to English every doc the code branches did not touch: AGENT.md,
  developer guide, vibe, CHANGELOG, docs index, module pages, all skills
  except ipal-seo-check (14 pages follow after the security/SEO merge).
  Placeholder marker is now [TO FILL: …]; skill resources renamed to
  section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer
  block say the docs are in English.
- docs/seeding.md: create-only, natural keys, never delete, no users or
  secrets, empty-field globals, fallbackLocale: false, dry run, backup and
  restore, production update guard, seeds vs migrations, Coolify Terminal.
  Seed templates gain --dry-run, the SEED_UPDATE production guard
  (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary.
  "Seeding on production" rule block in AGENT.md.
- Coolify is the single deployment path (deployment, env, developer guide,
  ipal-setup): build vs runtime env, migrations on container start
  (prodMigrations), health check and rolling updates, rollback, backups and
  restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone;
  default is media served by the app (R2_PUBLIC_URL empty).
- docsConsistency: no Polish prose outside code/quoted data (pending pages
  listed); IPAL_* names may also be read by shipped skill templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:39:03 +02:00

167 lines
9.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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 }` for `markdownRoute` |
| `markdownAlternate` | off | `true`/prefix → `generatePageMetadata` adds `<link rel="alternate" type="text/markdown">` (indexable pages) |
| `mcp` | — | `{ serverName, serverVersion, rateLimit, maxBatch, clientIp }` for `mcpGET`/`mcpPOST` (mcp.md) |
| `pageJsonLd` | — | default `getPageJsonLd` options: `breadcrumbs`, `entryType`, `entries`, `faq`, `pageType` |
| `robots` | — | `RobotsOptions` for `robots` (seo.md) |
| `siteJsonLd` | WebSite + Organization from Site Settings | a function replaces it, `false` = none |
| `sitemapImages` | the document's SEO image | `(doc) => url[]` |
| `sitemapStyle` | built-in style | `false` = raw XML |
| `summaryField` | — | field from `buildSummaryField` for llms.txt / MCP |
### Returned keys (what `@/lib/content` exports)
| Key | Signature / usage |
|---|---|
| `getCachedPayload` | `() => Promise<Payload>` |
| `getConfiguredLocales` | `() => Promise<string[]>` (from `config.localization`) |
| `getSettings` | `(locale)` — SiteSettings, `depth: 2`, 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 }` (database error → `[]`) |
| `sitemapRoute` | `app/sitemap.xml/route.ts`: `export { sitemapRoute as GET }` |
| `robots` | `app/robots.ts`: `export { robots as default }` |
| `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) |
| `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 in `createContentHelpers.ts` (~470) talks about content collections, but the code (~512–518)
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, …blockProps }` → `render` (optional) → `<JsonLdGraph>`.
| 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)} logEndpoint="/api/ipal/consent">
<Header /><main>{children}</main><Footer />
</SiteProviders>
</body>
```
Renders: `<ThemeScript>` (when `theme`), `<MediaPreconnect>`, `<JsonLdGraph>` (site JSON-LD + `jsonLd`),
`<ConsentProvider>` with `<TurnstileProvider>`, `<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` | — | consent log endpoint (`consentLog`) |
| `banner` | `<CookieBanner />` | your own banner or `false` |
| `cookieButton` | `<CookieButton />` | your own button or `false` |
| `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 |
| `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`: `banner`, `cookieButton`, `analytics` accept your own element or `false`.
- `createPageRoute` pagination and the `generateStaticParams` scope currently cannot be changed with an option — only with your own code.