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]>
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
type ProductPrice = {
|
|
amount: number
|
|
currency: string
|
|
/** 'exact' → Offer.price; 'from' → minPrice (a starting price, not a promise). */
|
|
kind?: 'exact' | 'from'
|
|
}
|
|
|
|
type ProductJsonLdArgs = {
|
|
/** schema.org availability, e.g. 'MadeToOrder', 'InStock'. Default 'InStock' when a price is given. */
|
|
availability?: string
|
|
brand?: string
|
|
category?: string
|
|
description?: string
|
|
/** Absolute image URL. */
|
|
image?: string
|
|
name: string
|
|
/** Only a real price from the panel — no price (on request) → no Offer at all. */
|
|
price?: null | ProductPrice
|
|
sku?: string
|
|
/** Absolute URL of the product page (also its @id). */
|
|
url: string
|
|
}
|
|
|
|
/**
|
|
* schema.org Product for a catalog entry: name, SKU, image, category, brand and —
|
|
* only when the panel has one — an Offer. A product "on request" gets no Offer:
|
|
* an invented or estimated price in structured data misleads search results.
|
|
*
|
|
* createContentHelpers({ pageJsonLd: { entries: {
|
|
* products: ({ doc, url, image }) => buildProductJsonLd({ name: doc.title, sku: doc.sku, url, image, … }),
|
|
* } } })
|
|
*/
|
|
export function buildProductJsonLd({
|
|
name,
|
|
availability,
|
|
brand,
|
|
category,
|
|
description,
|
|
image,
|
|
price,
|
|
sku,
|
|
url,
|
|
}: ProductJsonLdArgs): Record<string, unknown> {
|
|
const offer =
|
|
price && Number.isFinite(price.amount) && price.currency
|
|
? {
|
|
'@type': 'Offer',
|
|
availability: `https://schema.org/${availability ?? 'InStock'}`,
|
|
priceCurrency: price.currency,
|
|
url,
|
|
...(price.kind === 'from'
|
|
? { priceSpecification: { '@type': 'PriceSpecification', minPrice: price.amount, priceCurrency: price.currency } }
|
|
: { price: price.amount }),
|
|
}
|
|
: undefined
|
|
return {
|
|
name,
|
|
'@context': 'https://schema.org',
|
|
'@id': url,
|
|
'@type': 'Product',
|
|
url,
|
|
...(sku ? { sku } : {}),
|
|
...(description ? { description } : {}),
|
|
...(image ? { image } : {}),
|
|
...(category ? { category } : {}),
|
|
...(brand ? { brand: { name: brand, '@type': 'Brand' } } : {}),
|
|
...(offer ? { offers: offer } : {}),
|
|
}
|
|
}
|