Block library: item headings follow the section; the leading block's first image is the LCP image

Found by ipal-doctor live-seo on the reference archive pages (entry list under a
page header without a picture): cards jumped h1 → h3, and the first card image
was lazy.

- itemHeadingLevel: items one below the section heading (h3 under h2, h2 under the
  page h1, h2 when the block shows no heading); createBlockRegistry({ itemHeadings })
  fixes a level per block. featureGrid, entryList, pricing, steps, team.
- blockPosition / blockHasImage (root): createPageRoute and the 404 view pass
  firstImage next to isFirst; leadsWithImage marks the first image of the leading
  block eager + fetchPriority high (hero, textMedia, featureGrid, gallery, team,
  entryList); priorityImage: false turns it off.
- reference/ipal-doctor.json: the two live-seo silences removed; reference skills
  and docs/agent/reference-site/INDEX.md refreshed.
- bin/ipal-blocks.mjs executable like the other bins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 16:38:04 +01:00
co-authored by Claude Opus 5.5
parent dd11bc8146
commit 6f56ef4205
27 changed files with 206 additions and 53 deletions
+1
View File
@@ -1,3 +1,4 @@
export { blockHasImage, blockPosition } from './position.js'
export { RenderBlocks } from './RenderBlocks.js'
export type { RenderBlocksProps } from './RenderBlocks.js'
export { buildSectionHeaderField, buildSectionSettingsField } from './sectionFields.js'
+27
View File
@@ -0,0 +1,27 @@
import type { BlockData } from './types.js'
const isImage = (v: unknown): boolean => {
if (!v || typeof v !== 'object') {return false}
const doc = v as { height?: unknown; mimeType?: unknown; url?: unknown; width?: unknown }
if (typeof doc.url !== 'string') {return false}
if (typeof doc.mimeType === 'string') {return doc.mimeType.startsWith('image/')}
return typeof doc.height === 'number' && typeof doc.width === 'number'
}
/** True when the block's data holds a populated image anywhere (media, items[].media …). */
export function blockHasImage(value: unknown, depth = 0): boolean {
if (depth > 6 || !value || typeof value !== 'object') {return false}
if (isImage(value)) {return true}
return (Array.isArray(value) ? value : Object.values(value)).some((v) => blockHasImage(v, depth + 1))
}
/**
* Where a block sits on the page, for headings and the LCP image:
* - `isFirst` — the first section: its heading is the page's only h1;
* - `firstImage` — no block before it shows an image, so its first image is likely the page's LCP image
* (e.g. an entry list under a page header without a picture) and should load eagerly with high priority.
* createPageRoute passes both to every block; use it in your own `enhanceProps`.
*/
export function blockPosition({ allBlocks, index }: { allBlocks: BlockData[]; index: number }): { firstImage: boolean; isFirst: boolean } {
return { firstImage: !allBlocks.slice(0, index).some((b) => blockHasImage(b)), isFirst: index === 0 }
}