Page-filled form fields, links to entries, entry JSON-LD, R2-optional dev

Forms: `values` on RenderForm / BuilderForm / useBuilderForm fills fields the
page knows (chosen product variant, category) — read-only <output>, in the
SSR HTML, sent and validated like any field. prepareBuilderForm (/rsc) is the
server half of RenderForm for client components whose values change in the
browser; publicForm is exported so projects stop copying it.

Links: buildLinkField({ relationTo: ['pages', 'categories', …] }) — a
polymorphic relation; resolveLinkHref builds /{locale}/{archive}/{entry} from
`archives`, which getLinkOptions in createContentHelpers fills from Site
Settings.

SEO: pageJsonLd.entries — the main JSON-LD node per content collection
instead of BlogPosting; buildProductJsonLd emits an Offer only for a real
price from the panel.

Pages: createPageRoute / createNotFoundPage pass isFirst to blocks, so the
first section carries the page's only h1.

Fixes: ipalEnvRules({ storage: true }) requires R2_* in production only
(development: optional, all or none); buildImagesConfig allows the app's own
media on localhost outside production.

Docs, CHANGELOG, PROGRAMISTA §6 (34–37), ipal-form and ipal-upgrade skills.
Tests: builderForm, links, drafts (entries + archives), seo, media, env.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-19 19:38:28 +02:00
co-authored by Claude Opus 5.5
parent 46d30d4ecd
commit f809526f1d
31 changed files with 551 additions and 54 deletions
+43 -3
View File
@@ -19,6 +19,7 @@ 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 { archiveFieldName } from '../content/types.js'
import { createHealthRoute } from '../health/createHealthRoute.js'
import { homeSlugFrom, resolveLink as resolveLinkRaw, resolveNav as resolveNavRaw, resolveSystemLinks } from '../links/resolveNav.js'
import { createMcpRoute } from '../mcp/createMcpRoute.js'
@@ -94,9 +95,30 @@ type CreateContentHelpersArgs = {
summaryField?: string
}
/** What an entry's own JSON-LD builder gets (PageJsonLdOptions.entries). */
export type EntryJsonLdContext = {
/** Archive page of the entry (title, slug). */
archive: Record<string, unknown>
/** Meta description (SEO tab or the site's description). */
description?: string
doc: Record<string, unknown>
/** Absolute share-image URL. */
image?: string
locale: string
siteName?: string
/** Absolute canonical URL of the entry. */
url: string
}
export type PageJsonLdOptions = {
/** BreadcrumbList (home › archive › page) from the real route. Default true. */
breadcrumbs?: boolean
/**
* The main node per content collection, instead of the article (`entryType`):
* `{ products: (ctx) => buildProductJsonLd({…}), categories: (ctx) => buildWebPageJsonLd({ type: 'CollectionPage', … }) }`.
* Return null to emit no main node. Breadcrumbs and FAQ still follow.
*/
entries?: Record<string, (ctx: EntryJsonLdContext) => null | Record<string, unknown>>
/** schema.org type of archive entries. Default 'BlogPosting'. */
entryType?: 'Article' | 'BlogPosting' | 'NewsArticle'
/**
@@ -270,7 +292,10 @@ export function createContentHelpers({
const image = meta.openGraph?.images?.[0]?.url
const nodes: (null | Record<string, unknown>)[] = []
if (route.type === 'entry') {
const entryNode = route.type === 'entry' ? opts.entries?.[route.collection] : undefined
if (route.type === 'entry' && entryNode) {
nodes.push(entryNode({ archive: route.archive, description: meta.description, doc, image, locale, siteName, url }))
} else if (route.type === 'entry') {
nodes.push(
buildArticleJsonLd({
type: opts.entryType ?? 'BlogPosting',
@@ -572,8 +597,23 @@ export function createContentHelpers({
/** 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 } : {}) }
const settings = await getSettings(locale)
const homeSlug = homeSlugFrom(settings)
// Archive page per content collection → links to entries (categories, products…) resolve too.
const archives = Object.fromEntries(
(content?.collections ?? []).flatMap(({ slug }) => {
const archive = (settings as Record<string, unknown>)[archiveFieldName(slug)]
const archiveSlug = archive && typeof archive === 'object' ? (archive as { slug?: unknown }).slug : undefined
return typeof archiveSlug === 'string' && archiveSlug ? [[slug, archiveSlug]] : []
}),
)
return {
config: needI18n('getLinkOptions'),
locale,
pagesSlug,
...(homeSlug ? { homeSlug } : {}),
...(Object.keys(archives).length ? { archives } : {}),
}
}
/**
+7 -3
View File
@@ -17,7 +17,11 @@ type Helpers = Partial<Pick<ContentHelpers, 'getConstructionMode'>> & Pick<
type BlockPropsContext = { doc: Record<string, unknown>; locale: string }
export type PageRouteOptions = {
/** Props for every block on top of `locale`, computed once per page — e.g. `{ formTexts, sendForm }` for form blocks. */
/**
* Props for every block on top of `locale` and `isFirst` (true for the first
* section — its heading is the page's only h1), computed once per page —
* e.g. `{ formTexts, sendForm }` for form blocks.
*/
blockProps?: (ctx: BlockPropsContext) => Promise<Record<string, unknown>> | Record<string, unknown>
/** blockType → component (the project's registry). */
blocks: BlockComponentMap
@@ -97,7 +101,7 @@ export function createPageRoute(helpers: Helpers, options: PageRouteOptions) {
<RenderBlocks
blocks={doc[layoutField] as BlockData[] | undefined}
components={blocks}
enhanceProps={() => ({ locale, ...extra })}
enhanceProps={({ index }) => ({ locale, ...extra, isFirst: index === 0 })}
/>
)
const custom = render ? await render({ blocks: rendered, locale, route, segments }) : undefined
@@ -142,7 +146,7 @@ export function createNotFoundPage(helpers: Helpers, options: NotFoundPageOption
const fb = typeof fallback === 'function' ? fallback(locale) : fallback
if (!doc || !layout?.length) {return [locale, fb] as const}
const extra = blockProps ? await blockProps({ doc, locale }) : {}
return [locale, <RenderBlocks blocks={layout} components={blocks} enhanceProps={() => ({ locale, ...extra })} key={locale} />] as const
return [locale, <RenderBlocks blocks={layout} components={blocks} enhanceProps={({ index }) => ({ locale, ...extra, isFirst: index === 0 })} key={locale} />] as const
}),
),
)