Import instead of code: panel forms (steps, choice lists, dates), layout, page route, GEO routes, links, section fields

- Forms: step and checkboxGroup field types (radio, date on), server validation for them,
  useBuilderForm (logic) + BuilderForm (unstyled default) + RenderForm (/rsc: rich text,
  bound action, public part of the form only — the Emails tab never reaches the browser)
- Notifications: next / back / stepOf texts
- createContentHelpers: getSiteShell, getFormTexts, getLinkOptions, resolveLink, resolveNav,
  resolvePageRedirect, one-line route handlers (llms, llms-full, md, mcp, health, indexnow, manifest)
- /rsc: SiteProviders, createPageRoute, createNotFoundPage
- resolveLink / resolveNav / homeSlugFrom, buildSectionHeaderField / buildSectionSettingsField
- Dev sandbox frontend built on these imports; tests (unit + real Payload)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-16 11:32:46 +02:00
co-authored by Claude Opus 5.5
parent 0cfd846dd1
commit 412bf953a8
44 changed files with 2015 additions and 20 deletions
+178 -1
View File
@@ -3,14 +3,32 @@ import type { BasePayload, SanitizedConfig } from 'payload'
import { getPayload } from 'payload'
import { cache } from 'react'
import type { AnalyticsConfig } from '../analytics/types.js'
import type { ConsentTexts } from '../consent/texts.js'
import type { ArchiveEntries, ContentOption, ResolvedRoute } from '../content/index.js'
import type { I18nConfig } from '../i18n/index.js'
import type { LinkValue, NavItem, ResolvedLink, ResolveLinkHrefOptions } from '../links/index.js'
import type { CreateMcpRouteArgs } from '../mcp/createMcpRoute.js'
import type { FormNotificationTexts } from '../notifications/types.js'
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapStyleOptions } from '../seo/index.js'
import { getAnalyticsConfig } from '../analytics/getAnalyticsConfig.js'
import { getConsentTexts } from '../consent/getConsentTexts.js'
import { createMarkdownRoute } from '../content/createMarkdownRenderer.js'
import { getArchiveEntries, resolveRoute as resolveRouteRaw } from '../content/index.js'
import { MARKDOWN_PREFIX, markdownHref } from '../content/markdownNegotiation.js'
import { resolveRedirect as resolveRedirectRaw } from '../content/resolveRedirect.js'
import { createHealthRoute } from '../health/createHealthRoute.js'
import { homeSlugFrom, resolveLink as resolveLinkRaw, resolveNav as resolveNavRaw } from '../links/resolveNav.js'
import { createMcpRoute } from '../mcp/createMcpRoute.js'
import { getNotificationTexts } from '../notifications/getNotificationTexts.js'
import { buildOrganizationJsonLd, sameAsUrls } from '../seo/buildOrganizationJsonLd.js'
import { buildWebPageJsonLd } from '../seo/buildWebPageJsonLd.js'
import { buildArticleJsonLd, buildBreadcrumbJsonLd, buildFaqJsonLd, buildRobots, buildSitemapEntries, createPageMetadata, createSitemapRouteHandler } from '../seo/index.js'
import { buildWebSiteJsonLd } from '../seo/buildWebSiteJsonLd.js'
import { buildArticleJsonLd, buildBreadcrumbJsonLd, buildFaqJsonLd, buildRobots, buildSitemapEntries, createManifestHandler, createPageMetadata, createSitemapRouteHandler } from '../seo/index.js'
import { createIndexNowKeyRoute } from '../seo/indexNow.js'
import { createLlmsTxtRoute } from '../seo/routeHandlers.js'
import { getTurnstileConfig } from '../turnstile/config.js'
type CreateContentHelpersArgs = {
/**
@@ -31,6 +49,8 @@ type CreateContentHelpersArgs = {
* handlers — they need the locale list to emit hreflang.
*/
i18n?: I18nConfig
/** Markdown route (`markdownRoute`): per-block overrides, frontmatter, layout field. */
markdown?: { frontmatter?: boolean; layoutField?: string; overrides?: Record<string, (block: Record<string, unknown>) => string> }
/**
* Advertise each page's Markdown version from generatePageMetadata:
* `<link rel="alternate" type="text/markdown" href="/md/pl/o-nas">` (GEO —
@@ -39,10 +59,14 @@ type CreateContentHelpersArgs = {
* (content.md). Indexable pages only.
*/
markdownAlternate?: boolean | string
/** MCP route (`mcpRoute`): server name/version, rate limit, batch size. */
mcp?: Pick<CreateMcpRouteArgs, 'clientIp' | 'maxBatch' | 'rateLimit' | 'serverName' | 'serverVersion'>
/** Defaults for getPageJsonLd — each call can override them. */
pageJsonLd?: PageJsonLdOptions
/** Pages collection slug. Defaults to 'pages'. */
pagesSlug?: string
/** Collections checked for an old slug before a 404 (`resolvePageRedirect`). Default pages. */
redirectCollections?: { historyField?: string; slug: string; slugField?: string }[]
/**
* Options for the ready-made `robots` handler, e.g.
* `{ disallowParams: ['s', 'meter'], aiBots: 'block-training' }`, or
@@ -51,6 +75,13 @@ type CreateContentHelpersArgs = {
robots?: RobotsOptions
/** SiteSettings global slug. Defaults to 'site-settings'. */
settingsSlug?: string
/**
* Site-wide JSON-LD for `getSiteShell` (layout). Default: WebSite + Organization
* from Site Settings (siteName, logo, sameAs) — skipped when the name or the
* origin is missing, never a fallback name. A function replaces it (e.g.
* LocalBusiness from the Company global); `false` = none.
*/
siteJsonLd?: ((ctx: { baseUrl: string; locale: string; settings: Record<string, unknown> }) => Promise<Record<string, unknown>[]> | Record<string, unknown>[]) | false
/** Image URLs of a document for the sitemap (Google Images). Default: its SEO share image. */
sitemapImages?: (doc: Record<string, unknown>) => (null | string | undefined)[]
/**
@@ -58,6 +89,8 @@ type CreateContentHelpersArgs = {
* header "XML Sitemap", credit "Technology by Intecion.com". `false` = raw XML.
*/
sitemapStyle?: false | SitemapStyleOptions
/** Field with the AI summary (buildSummaryField) — llms.txt and MCP prefer it. */
summaryField?: string
}
export type PageJsonLdOptions = {
@@ -105,13 +138,18 @@ export function createContentHelpers({
config,
content,
i18n,
markdown: markdownOptions,
markdownAlternate,
mcp: mcpOptions,
pageJsonLd: pageJsonLdDefaults,
pagesSlug = 'pages',
redirectCollections,
robots: robotsOptions,
settingsSlug = 'site-settings',
siteJsonLd,
sitemapImages,
sitemapStyle,
summaryField,
}: CreateContentHelpersArgs) {
const origin = baseUrl ?? process.env.NEXT_PUBLIC_SERVER_URL ?? ''
const getCachedPayload = cache(
@@ -522,18 +560,157 @@ export function createContentHelpers({
*/
const sitemapRoute = createSitemapRouteHandler(sitemap, { style: sitemapStyle ?? {} })
const needI18n = (what: string): I18nConfig => {
if (!i18n) {throw new Error(`[ipal] createContentHelpers: pass \`i18n\` to use ${what}.`)}
return i18n
}
// ── Links & navigation ────────────────────────────────────────────────────
/** Homepage slug in this locale (SiteSettings.homepage) — links to it collapse to /{locale}. */
const getHomeSlug = async (locale: string) => homeSlugFrom(await getSettings(locale))
/** Options for resolveLinkHref / resolveLink / RenderForm `linkOptions` in this locale. */
const getLinkOptions = async (locale: string): Promise<ResolveLinkHrefOptions> => {
const homeSlug = await getHomeSlug(locale)
return { config: needI18n('getLinkOptions'), locale, ...(homeSlug ? { homeSlug } : {}) }
}
/**
* A panel link → `{ href, label, internal, newTab, targetProps, appearance }`
* or null. The project's CMSLink only picks the element and the classes.
*/
const resolveLink = async (link: LinkValue | null | undefined, locale: string): Promise<null | ResolvedLink> =>
resolveLinkRaw(link, await getLinkOptions(locale))
/** Menu items of a Header/Footer global → serializable NavItem[] (pass to a client MobileNav as is). */
const resolveNav = async (items: unknown, locale: string, options: { childrenField?: string; linkField?: string } = {}): Promise<NavItem[]> =>
resolveNavRaw(items, { ...(await getLinkOptions(locale)), ...options })
/** Old slug → its new URL (308), for the catch-all page before notFound(). */
const resolvePageRedirect = async (locale: string, segments: string[] | undefined): Promise<null | string> =>
resolveRedirectRaw({
collections: redirectCollections,
config: needI18n('resolvePageRedirect'),
homeSlug: await getHomeSlug(locale),
locale,
payload: await getCachedPayload(),
segments,
})
// ── Layout ────────────────────────────────────────────────────────────────
/** Notifications → form texts in this locale (BuilderForm / RenderForm `texts`). */
const getFormTexts = cache(async (locale: string): Promise<FormNotificationTexts> =>
(await getNotificationTexts({ locale, payload: await getCachedPayload() })).form,
)
/**
* Everything the [locale] layout reads, in one cached call: consent texts,
* analytics IDs, Turnstile site key, site JSON-LD, form texts and Site
* Settings. Feed it to <SiteProviders> (/rsc) — or use the pieces yourself.
*/
const getSiteShell = cache(async (locale: string): Promise<SiteShell> => {
const payload = await getCachedPayload()
const [consent, analytics, turnstile, settings, formTexts] = await Promise.all([
getConsentTexts({ config: needI18n('getSiteShell'), locale, payload, settingsSlug }),
getAnalyticsConfig(payload),
getTurnstileConfig(payload),
getSettings(locale) as Promise<Record<string, unknown>>,
getFormTexts(locale),
])
let jsonLd: Record<string, unknown>[] = []
if (typeof siteJsonLd === 'function') {
jsonLd = await siteJsonLd({ baseUrl: origin, locale, settings: settings ?? {} })
} else if (siteJsonLd !== false) {
const name = typeof settings?.siteName === 'string' && settings.siteName.trim() ? settings.siteName.trim() : undefined
if (name && origin) {
jsonLd = [
buildWebSiteJsonLd({ name, url: origin }),
buildOrganizationJsonLd({ name, logo: settings.logo as never, sameAs: sameAsUrls(settings), url: origin }),
]
}
}
return {
analytics,
consent,
formTexts,
jsonLd: jsonLd.map(({ '@context': _context, ...node }) => node),
settings: settings ?? {},
turnstileSiteKey: turnstile.siteKey,
}
})
// ── Ready route handlers (one line per route file) ────────────────────────
// Created on first request, so a project that doesn't use one pays nothing
// and a missing option only fails the route that needs it.
const lazy = <T>(make: () => T) => {
let value: T | undefined
return () => (value ??= make())
}
const llms = lazy(() => createLlmsTxtRoute({ baseUrl: origin, config: needI18n('llmsRoute'), content, getCachedPayload, pagesSlug, settingsSlug, summaryField }))
const llmsFull = lazy(() => createLlmsTxtRoute({ baseUrl: origin, config: needI18n('llmsFullRoute'), content, full: true, getCachedPayload, pagesSlug, settingsSlug, summaryField }))
const md = lazy(() => createMarkdownRoute({ baseUrl: origin || undefined, collection: pagesSlug, config: i18n, content, getCachedPayload, settingsSlug, ...markdownOptions }))
const mcp = lazy(() => createMcpRoute({ baseUrl: origin, collection: pagesSlug, config: needI18n('mcpRoute'), content, getCachedPayload, settingsSlug, summaryField, ...mcpOptions }))
const health = lazy(() => createHealthRoute({ collection: pagesSlug, getCachedPayload }))
const indexNowKey = lazy(() => createIndexNowKeyRoute({ getCachedPayload }))
const manifestHandler = lazy(() => createManifestHandler({ config: needI18n('manifest'), getCachedPayload, settingsSlug }))
/** app/llms.txt/route.ts: `export { llmsRoute as GET } from '@/lib/content'` */
const llmsRoute = () => llms()()
/** app/llms-full.txt/route.ts: `export { llmsFullRoute as GET } from '@/lib/content'` */
const llmsFullRoute = () => llmsFull()()
/** app/md/[locale]/[[...slug]]/route.ts: `export { markdownRoute as GET } from '@/lib/content'` */
const markdownRoute = (req: Request, ctx: { params: Promise<{ locale: string; slug?: string[] }> }) => md().GET(req, ctx)
/** app/api/mcp/route.ts: `export { mcpGET as GET, mcpPOST as POST } from '@/lib/content'` */
const mcpGET = () => mcp().GET()
const mcpPOST = (req: Request) => mcp().POST(req)
/** app/api/health/route.ts: `export { healthRoute as GET } from '@/lib/content'` */
const healthRoute = () => health()()
/** app/indexnow-key.txt/route.ts: `export { indexNowKeyRoute as GET } from '@/lib/content'` */
const indexNowKeyRoute = () => indexNowKey()()
/** app/manifest.ts: `export { manifest as default } from '@/lib/content'` */
const manifest = () => manifestHandler()()
return {
generatePageMetadata,
generateStaticParams,
getCachedPayload,
getConfiguredLocales,
getEntries,
getFormTexts,
getHomeSlug,
getLinkOptions,
getNotFoundPage,
getPageJsonLd,
getSettings,
getSiteShell,
healthRoute,
i18n,
indexNowKeyRoute,
llmsFullRoute,
llmsRoute,
manifest,
markdownRoute,
mcpGET,
mcpPOST,
resolveLink,
resolveNav,
resolvePageRedirect,
resolveRoute,
robots,
sitemap,
sitemapRoute,
}
}
/** What the layout needs — getSiteShell(locale). Plain data, safe to pass to client components. */
export type SiteShell = {
analytics: AnalyticsConfig
consent: ConsentTexts
formTexts: FormNotificationTexts
/** Site-wide nodes (WebSite, Organization…) for <JsonLdGraph>. */
jsonLd: Record<string, unknown>[]
settings: Record<string, unknown>
turnstileSiteKey: null | string
}
export type ContentHelpers = ReturnType<typeof createContentHelpers>