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:
co-authored by
Claude Opus 5.5
parent
dd11bc8146
commit
6f56ef4205
@@ -54,6 +54,8 @@ export { Container, CONTAINER_WIDTHS } from '../modules/block-library/ui/Contain
|
||||
export type { ContainerProps, ContainerWidth } from '../modules/block-library/ui/Container.js'
|
||||
export { cx, parts } from '../modules/block-library/ui/cx.js'
|
||||
export type { PartClasses } from '../modules/block-library/ui/cx.js'
|
||||
export { itemHeadingLevel, leadsWithImage } from '../modules/block-library/ui/levels.js'
|
||||
export type { ItemHeadingLevel } from '../modules/block-library/ui/levels.js'
|
||||
export { Media } from '../modules/block-library/ui/Media.js'
|
||||
export type { ImageComponent, MediaProps } from '../modules/block-library/ui/Media.js'
|
||||
export { Section, SECTION_BACKGROUNDS } from '../modules/block-library/ui/Section.js'
|
||||
|
||||
@@ -32,6 +32,7 @@ export type { AnalyticsConfig } from './modules/analytics/index.js'
|
||||
export { getAnalyticsConfig } from './modules/analytics/index.js'
|
||||
export { shouldLoadGoogle } from './modules/analytics/shouldLoadGoogle.js'
|
||||
// Shared section fields (header: eyebrow/heading/intro, settings: anchor/background).
|
||||
export { blockHasImage, blockPosition } from './modules/blocks/position.js'
|
||||
export { buildSectionHeaderField, buildSectionSettingsField } from './modules/blocks/sectionFields.js'
|
||||
export type { SectionHeaderFieldOptions, SectionSettingsFieldOptions } from './modules/blocks/sectionFields.js'
|
||||
export { buildAdminImageEndpoints } from './modules/branding/adminImages.js'
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { BaseBlockData } from '../../data.js'
|
||||
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { Buttons, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { itemHeadingLevel, leadsWithImage } from '../../ui/levels.js'
|
||||
import { TitleLink } from '../../ui/TitleLink.js'
|
||||
|
||||
export type EntryListBlockData = {
|
||||
@@ -53,6 +54,8 @@ export async function EntryListBlock(props: LibraryBlockProps<EntryListBlockData
|
||||
const c = parts(ENTRY_LIST_PARTS, classNames)
|
||||
const id = headingId(props)
|
||||
const dates = new Intl.DateTimeFormat(locale, { dateStyle: 'long' })
|
||||
const H = itemHeadingLevel('entryList', props)
|
||||
const lead = leadsWithImage(props)
|
||||
return (
|
||||
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
|
||||
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
|
||||
@@ -60,14 +63,14 @@ export async function EntryListBlock(props: LibraryBlockProps<EntryListBlockData
|
||||
{rows.map(({ card, collection: from, doc }, i) => (
|
||||
<li className="flex" key={typeof doc.id === 'string' || typeof doc.id === 'number' ? doc.id : i}>
|
||||
<ui.Card className={cx('w-full', c.card)} interactive>
|
||||
{variant === 'list' ? null : <ui.Media className={c.media} resource={card.media as never} sizes={MEDIA_SIZES.third} />}
|
||||
{variant === 'list' ? null : <ui.Media className={c.media} priority={lead && i === 0} resource={card.media as never} sizes={MEDIA_SIZES.third} />}
|
||||
<div className="flex flex-col gap-2 p-6 pt-0 first:pt-6">
|
||||
{card.date ? <time className={c.date} dateTime={card.date}>{dates.format(new Date(card.date))}</time> : null}
|
||||
<h3 className={c.title}>
|
||||
<H className={c.title}>
|
||||
<TitleLink link={{ type: 'internal', page: { relationTo: from, value: doc } }} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink}>
|
||||
{card.title}
|
||||
</TitleLink>
|
||||
</h3>
|
||||
</H>
|
||||
{card.text ? <p className={c.text}>{card.text}</p> : null}
|
||||
</div>
|
||||
</ui.Card>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import type { BlockContext, BlockUi, LibraryBlockProps } from '../../context.js'
|
||||
import type { BaseBlockData, LinkData, MediaValue } from '../../data.js'
|
||||
import type { ItemHeadingLevel } from '../../ui/levels.js'
|
||||
|
||||
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { Buttons, GRID_COLUMNS, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { itemHeadingLevel, leadsWithImage } from '../../ui/levels.js'
|
||||
import { TitleLink } from '../../ui/TitleLink.js'
|
||||
|
||||
export type FeatureItem = { heading: string; icon?: null | string; id?: null | string; link?: LinkData; media?: MediaValue; text?: null | string }
|
||||
@@ -28,13 +30,15 @@ export function FeatureGridBlock(props: LibraryBlockProps<FeatureGridBlockData>)
|
||||
const id = headingId(props)
|
||||
const v = variant ?? 'cards'
|
||||
const List = v === 'numbered' ? 'ol' : 'ul'
|
||||
const H = itemHeadingLevel('featureGrid', props)
|
||||
const lead = leadsWithImage(props)
|
||||
return (
|
||||
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
|
||||
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
|
||||
<List className={cx(v === 'list' ? c.list : c.grid, GRID_COLUMNS[columns ?? 'three'])}>
|
||||
{items.map((item, i) => (
|
||||
<li className="flex" key={item.id ?? i}>
|
||||
<FeatureCard c={c} ctx={ctx} index={v === 'numbered' ? i + 1 : undefined} item={item} locale={locale} plain={v === 'list'} ui={ui} />
|
||||
<FeatureCard as={H} c={c} ctx={ctx} index={v === 'numbered' ? i + 1 : undefined} item={item} locale={locale} plain={v === 'list'} priority={lead && i === 0} ui={ui} />
|
||||
</li>
|
||||
))}
|
||||
</List>
|
||||
@@ -43,7 +47,7 @@ export function FeatureGridBlock(props: LibraryBlockProps<FeatureGridBlockData>)
|
||||
)
|
||||
}
|
||||
|
||||
function FeatureCard({ c, ctx, index, item, locale, plain, ui }: { c: typeof FEATURE_GRID_PARTS; ctx: BlockContext; index?: number; item: FeatureItem; locale: string; plain: boolean; ui: BlockUi }) {
|
||||
function FeatureCard({ as: H, c, ctx, index, item, locale, plain, priority, ui }: { as: ItemHeadingLevel; c: typeof FEATURE_GRID_PARTS; ctx: BlockContext; index?: number; item: FeatureItem; locale: string; plain: boolean; priority: boolean; ui: BlockUi }) {
|
||||
const Icon = item.icon ? ctx.icons?.[item.icon] : undefined
|
||||
const heading = item.link ? (
|
||||
<TitleLink link={item.link} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink}>
|
||||
@@ -56,8 +60,8 @@ function FeatureCard({ c, ctx, index, item, locale, plain, ui }: { c: typeof FEA
|
||||
<>
|
||||
{index ? <span aria-hidden className={c.number}>{String(index).padStart(2, '0')}</span> : null}
|
||||
{Icon ? <Icon aria-hidden className={c.icon} /> : null}
|
||||
<ui.Media className={c.media} resource={item.media} sizes={MEDIA_SIZES.third} />
|
||||
<h3 className={c.heading}>{heading}</h3>
|
||||
<ui.Media className={c.media} priority={priority} resource={item.media} sizes={MEDIA_SIZES.third} />
|
||||
<H className={c.heading}>{heading}</H>
|
||||
{item.text ? <p className={c.text}>{item.text}</p> : null}
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { LightboxTrigger } from '../../../lightbox/LightboxProvider.js'
|
||||
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { Buttons, GRID_COLUMNS, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { leadsWithImage } from '../../ui/levels.js'
|
||||
|
||||
export type GalleryItem = { caption?: null | string; id?: null | string; media?: MediaValue }
|
||||
export type GalleryBlockData = { columns?: null | string; items?: GalleryItem[] | null } & BaseBlockData
|
||||
@@ -28,13 +29,14 @@ export function GalleryBlock(props: LibraryBlockProps<GalleryBlockData>) {
|
||||
const id = headingId(props)
|
||||
const group = `gallery-${props.id ?? 'block'}`
|
||||
const masonry = variant === 'masonry'
|
||||
const lead = leadsWithImage(props)
|
||||
const sizes = columns === 'two' ? MEDIA_SIZES.half : columns === 'four' ? MEDIA_SIZES.quarter : MEDIA_SIZES.third
|
||||
return (
|
||||
<ui.Section block={props.blockType} labelledBy={id} settings={settings} width="wide">
|
||||
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
|
||||
<ul className={masonry ? c.masonry : cx(c.grid, GRID_COLUMNS[columns ?? 'three'])}>
|
||||
{shown.map((item, i) => {
|
||||
const image = <ui.Media className={c.image} resource={item.media} sizes={sizes} />
|
||||
const image = <ui.Media className={c.image} priority={lead && i === 0} resource={item.media} sizes={sizes} />
|
||||
const large = ctx.lightbox ? lightboxImage(item.media, item.caption ? { caption: item.caption } : {}) : null
|
||||
return (
|
||||
<li key={item.id ?? i}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { BaseBlockData, MediaValue } from '../../data.js'
|
||||
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { Buttons, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { leadsWithImage } from '../../ui/levels.js'
|
||||
|
||||
export type HeroBlockData = { media?: MediaValue; poster?: MediaValue } & BaseBlockData
|
||||
|
||||
@@ -30,7 +31,7 @@ export function HeroBlock(props: LibraryBlockProps<HeroBlockData>) {
|
||||
if (v === 'background') {
|
||||
return (
|
||||
<ui.Section block={props.blockType} className={c.background} labelledBy={id} settings={{ ...settings, background: 'inverted' }}>
|
||||
<ui.Media alt="" className={c.backgroundMedia} poster={poster} priority={isFirst} resource={media} sizes={MEDIA_SIZES.full} videoMode="background" />
|
||||
<ui.Media alt="" className={c.backgroundMedia} poster={poster} priority={leadsWithImage({ ctx: props.ctx, firstImage: props.firstImage, isFirst })} resource={media} sizes={MEDIA_SIZES.full} videoMode="background" />
|
||||
<span aria-hidden className={c.backgroundOverlay} />
|
||||
<div className={c.page}>
|
||||
{title}
|
||||
@@ -47,7 +48,7 @@ export function HeroBlock(props: LibraryBlockProps<HeroBlockData>) {
|
||||
{title}
|
||||
{buttons}
|
||||
</div>
|
||||
{withMedia ? <ui.Media className={c.media} poster={poster} priority={isFirst} resource={media} sizes={MEDIA_SIZES.half} /> : null}
|
||||
{withMedia ? <ui.Media className={c.media} poster={poster} priority={leadsWithImage({ ctx: props.ctx, firstImage: props.firstImage, isFirst })} resource={media} sizes={MEDIA_SIZES.half} /> : null}
|
||||
</div>
|
||||
</ui.Section>
|
||||
)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import type { BlockUi, LibraryBlockProps } from '../../context.js'
|
||||
import type { BaseBlockData, LinkData } from '../../data.js'
|
||||
import type { ItemHeadingLevel } from '../../ui/levels.js'
|
||||
|
||||
import { headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { itemHeadingLevel } from '../../ui/levels.js'
|
||||
|
||||
export type PricingPlan = {
|
||||
features?: { id?: null | string; text: string }[] | null
|
||||
@@ -35,13 +37,14 @@ export function PricingBlock(props: LibraryBlockProps<PricingBlockData>) {
|
||||
if (!items?.length) {return null}
|
||||
const c = parts(PRICING_PARTS, classNames)
|
||||
const id = headingId(props)
|
||||
const H = itemHeadingLevel('pricing', props)
|
||||
return (
|
||||
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
|
||||
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
|
||||
<ul className={c.grid}>
|
||||
{items.map((plan, i) => (
|
||||
<li className="flex" key={plan.id ?? i}>
|
||||
<Plan c={c} highlightLabel={highlightLabel} locale={locale} plan={plan} ui={ui} />
|
||||
<Plan as={H} c={c} highlightLabel={highlightLabel} locale={locale} plan={plan} ui={ui} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -50,11 +53,11 @@ export function PricingBlock(props: LibraryBlockProps<PricingBlockData>) {
|
||||
)
|
||||
}
|
||||
|
||||
function Plan({ c, highlightLabel, locale, plan, ui }: { c: typeof PRICING_PARTS; highlightLabel?: null | string; locale: string; plan: PricingPlan; ui: BlockUi }) {
|
||||
function Plan({ as: H, c, highlightLabel, locale, plan, ui }: { as: ItemHeadingLevel; c: typeof PRICING_PARTS; highlightLabel?: null | string; locale: string; plan: PricingPlan; ui: BlockUi }) {
|
||||
return (
|
||||
<ui.Card className={cx('w-full', c.plan, plan.highlighted && c.highlighted)}>
|
||||
{plan.highlighted && highlightLabel ? <p className={c.badge}>{highlightLabel}</p> : null}
|
||||
<h3 className={c.name}>{plan.heading}</h3>
|
||||
<H className={c.name}>{plan.heading}</H>
|
||||
<p>
|
||||
<span className={c.price}>{plan.price}</span> {plan.period ? <span className={c.period}>{plan.period}</span> : null}
|
||||
</p>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { blockTexts, fillText } from '../../texts.js'
|
||||
import { Buttons, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { itemHeadingLevel } from '../../ui/levels.js'
|
||||
|
||||
export type StepItem = { heading: string; id?: null | string; media?: MediaValue; text?: null | string }
|
||||
export type StepsBlockData = { items?: null | StepItem[] } & BaseBlockData
|
||||
@@ -26,6 +27,7 @@ export function StepsBlock(props: LibraryBlockProps<StepsBlockData>) {
|
||||
const c = parts(STEPS_PARTS, classNames)
|
||||
const texts = blockTexts(locale, ctx.texts)
|
||||
const id = headingId(props)
|
||||
const H = itemHeadingLevel('steps', props)
|
||||
return (
|
||||
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
|
||||
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
|
||||
@@ -34,10 +36,10 @@ export function StepsBlock(props: LibraryBlockProps<StepsBlockData>) {
|
||||
<li className={c.item} key={s.id ?? i}>
|
||||
<span aria-hidden className={cx(c.number, 'relative')}>{i + 1}</span>
|
||||
<div>
|
||||
<h3 className={c.heading}>
|
||||
<H className={c.heading}>
|
||||
<span className="sr-only">{fillText(texts.step, i + 1)}: </span>
|
||||
{s.heading}
|
||||
</h3>
|
||||
</H>
|
||||
{s.text ? <p className={c.text}>{s.text}</p> : null}
|
||||
<ui.Media className={c.media} resource={s.media} sizes={MEDIA_SIZES.half} />
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { BaseBlockData, LinkData, MediaValue } from '../../data.js'
|
||||
import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { Buttons, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { itemHeadingLevel, leadsWithImage } from '../../ui/levels.js'
|
||||
import { TitleLink } from '../../ui/TitleLink.js'
|
||||
|
||||
export type TeamMember = { bio?: null | string; heading: string; id?: null | string; link?: LinkData; media?: MediaValue; text?: null | string }
|
||||
@@ -26,17 +27,19 @@ export function TeamBlock(props: LibraryBlockProps<TeamBlockData>) {
|
||||
const c = parts(TEAM_PARTS, classNames)
|
||||
const id = headingId(props)
|
||||
const list = variant === 'list'
|
||||
const H = itemHeadingLevel('team', props)
|
||||
const lead = leadsWithImage(props)
|
||||
return (
|
||||
<ui.Section block={props.blockType} labelledBy={id} settings={settings}>
|
||||
<ui.SectionHeader as={isFirst ? 'h1' : 'h2'} header={header} id={id} />
|
||||
<ul className={list ? c.list : c.grid}>
|
||||
{items.map((m, i) => (
|
||||
<li className={cx('flex flex-col gap-3', list && c.listItem)} key={m.id ?? i}>
|
||||
<ui.Media className={c.photo} resource={m.media} sizes={list ? '10rem' : MEDIA_SIZES.third} />
|
||||
<ui.Media className={c.photo} priority={lead && i === 0} resource={m.media} sizes={list ? '10rem' : MEDIA_SIZES.third} />
|
||||
<div className="flex flex-col gap-1">
|
||||
<h3 className={c.name}><TitleLink link={m.link} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink} stretch={false}>
|
||||
<H className={c.name}><TitleLink link={m.link} Link={ctx.Link} locale={locale} resolve={ctx.content.resolveLink} stretch={false}>
|
||||
{m.heading}
|
||||
</TitleLink></h3>
|
||||
</TitleLink></H>
|
||||
{m.text ? <p className={c.role}>{m.text}</p> : null}
|
||||
{m.bio ? <p className={c.bio}>{m.bio}</p> : null}
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { MEDIA_SIZES } from '../../../media/mediaProps.js'
|
||||
import { RenderRichText } from '../../../richtext/RenderRichText.js'
|
||||
import { Buttons, headingId } from '../../ui/Buttons.js'
|
||||
import { cx, parts } from '../../ui/cx.js'
|
||||
import { leadsWithImage } from '../../ui/levels.js'
|
||||
|
||||
export type TextMediaBlockData = { content?: RichTextData; media?: MediaValue } & BaseBlockData
|
||||
|
||||
@@ -30,7 +31,7 @@ export function TextMediaBlock(props: LibraryBlockProps<TextMediaBlockData>) {
|
||||
</div>
|
||||
{media ? (
|
||||
<div className={variant === 'mediaLeft' ? c.mediaLeft : undefined}>
|
||||
<ui.Media className={c.media} priority={isFirst} resource={media} sizes={MEDIA_SIZES.half} />
|
||||
<ui.Media className={c.media} priority={leadsWithImage(props)} resource={media} sizes={MEDIA_SIZES.half} />
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { BuilderFormClassNames } from '../forms/BuilderForm.js'
|
||||
import type { SendFormAction } from '../forms/RenderForm.js'
|
||||
import type { ResolveLinkHrefOptions } from '../links/resolveLinkHref.js'
|
||||
import type { BlockTexts } from './texts.js'
|
||||
import type { LibraryBlockSlug } from './types.js'
|
||||
import type { LinkComponent } from './ui/Anchor.js'
|
||||
import type { CardProps } from './ui/Card.js'
|
||||
import type { CMSLinkProps, ResolveLink } from './ui/CMSLink.js'
|
||||
@@ -54,12 +55,16 @@ export type BlockContext = {
|
||||
icons?: Record<string, ComponentType<{ 'aria-hidden'?: boolean; className?: string }>>
|
||||
/** next/image — optimized images with blur-up. Without it: a plain <img>. */
|
||||
Image?: ImageComponent
|
||||
/** Heading level of a block's items (cards, plans, steps), per block. Default: one below the section heading (itemHeadingLevel). */
|
||||
itemHeadings?: Partial<Record<LibraryBlockSlug, 'h2' | 'h3' | 'h4'>>
|
||||
/** Lightbox triggers on gallery images. Default true (needs <SiteProviders lightbox>). */
|
||||
lightbox: boolean
|
||||
/** next/link — client-side navigation for internal links. Without it: a plain <a>. */
|
||||
Link?: LinkComponent
|
||||
/** Turns a testimonials-collection document into an item. Default: quote, heading/author/name, text/role, media, rating. */
|
||||
mapTestimonial?: (doc: Record<string, unknown>) => null | TestimonialItem
|
||||
/** The first image of the leading block loads eagerly with high priority (LCP). Default true; `false` = never. */
|
||||
priorityImage?: boolean
|
||||
richText?: { className?: string }
|
||||
/** The project's sendForm server action (createSubmitAction) — the contact block needs it. */
|
||||
sendForm?: SendFormAction
|
||||
@@ -70,6 +75,8 @@ export type BlockContext = {
|
||||
export type LibraryBlockProps<D> = {
|
||||
classNames?: PartClasses
|
||||
ctx: BlockContext
|
||||
/** No block before this one shows an image (createPageRoute, blockPosition). */
|
||||
firstImage?: boolean
|
||||
isFirst?: boolean
|
||||
locale: string
|
||||
ui: BlockUi
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { BlockContext } from '../context.js'
|
||||
import type { SectionHeaderData } from '../data.js'
|
||||
import type { LibraryBlockSlug } from '../types.js'
|
||||
|
||||
export type ItemHeadingLevel = 'h2' | 'h3' | 'h4'
|
||||
|
||||
/**
|
||||
* The heading level of a block's items (cards, plans, steps): one below the section heading —
|
||||
* h3 under a section h2, h2 under the page h1 (first section) — and h2 when the block shows no
|
||||
* heading of its own, so a list right under the page header never jumps from h1 to h3.
|
||||
* `createBlockRegistry({ itemHeadings: { entryList: 'h3' } })` fixes a level per block.
|
||||
*/
|
||||
export function itemHeadingLevel(
|
||||
slug: LibraryBlockSlug,
|
||||
{ ctx, header, isFirst }: { ctx: Pick<BlockContext, 'itemHeadings'>; header?: null | SectionHeaderData; isFirst?: boolean },
|
||||
): ItemHeadingLevel {
|
||||
const own = ctx.itemHeadings?.[slug]
|
||||
if (own) {return own}
|
||||
return header?.heading && !isFirst ? 'h3' : 'h2'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the block's first image is the page's LCP image: the first section, or no block before it shows
|
||||
* an image (`firstImage` from createPageRoute — e.g. an entry list under a page header without a picture).
|
||||
* `createBlockRegistry({ priorityImage: false })` turns it off.
|
||||
*/
|
||||
export function leadsWithImage({ ctx, firstImage, isFirst }: { ctx: Pick<BlockContext, 'priorityImage'>; firstImage?: boolean; isFirst?: boolean }): boolean {
|
||||
if (ctx.priorityImage === false) {return false}
|
||||
return Boolean(firstImage ?? isFirst)
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import type { BlockComponentMap, BlockData } from '../blocks/types.js'
|
||||
import type { ResolvedRoute } from '../content/index.js'
|
||||
import type { ContentHelpers, PageJsonLdOptions } from './createContentHelpers.js'
|
||||
|
||||
import { blockPosition } from '../blocks/position.js'
|
||||
import { RenderBlocks } from '../blocks/RenderBlocks.js'
|
||||
import { constructionNoticeHref, isPathVisibleIn } from '../construction/logic.js'
|
||||
import { LocaleView } from '../pages/LocaleView.js'
|
||||
@@ -19,8 +20,9 @@ type BlockPropsContext = { doc: Record<string, unknown>; locale: string }
|
||||
|
||||
export type PageRouteOptions = {
|
||||
/**
|
||||
* 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 —
|
||||
* Props for every block on top of `locale`, `isFirst` (true for the first
|
||||
* section — its heading is the page's only h1) and `firstImage` (no block before it
|
||||
* shows an image — its first image is the LCP image, blockPosition), computed once per page —
|
||||
* e.g. `{ formTexts, sendForm }` for form blocks.
|
||||
*/
|
||||
blockProps?: (ctx: BlockPropsContext) => Promise<Record<string, unknown>> | Record<string, unknown>
|
||||
@@ -138,7 +140,7 @@ export function createPageRoute(helpers: Helpers, options: PageRouteOptions) {
|
||||
<RenderBlocks
|
||||
blocks={doc[layoutField] as BlockData[] | undefined}
|
||||
components={blocks}
|
||||
enhanceProps={({ index }) => ({ locale, ...extra, isFirst: index === 0 })}
|
||||
enhanceProps={(at) => ({ locale, ...extra, ...blockPosition(at) })}
|
||||
/>
|
||||
)
|
||||
const custom = render ? await render({ blocks: rendered, locale, route, segments }) : undefined
|
||||
@@ -190,7 +192,7 @@ async function notFoundView(helpers: NotFoundHelpers, options: NotFoundViewOptio
|
||||
const layout = doc?.[layoutField] as BlockData[] | undefined
|
||||
if (!doc || !layout?.length) {return typeof fallback === 'function' ? fallback(locale) : fallback}
|
||||
const extra = blockProps ? await blockProps({ doc, locale }) : {}
|
||||
return <RenderBlocks blocks={layout} components={blocks} enhanceProps={({ index }) => ({ locale, ...extra, isFirst: index === 0 })} />
|
||||
return <RenderBlocks blocks={layout} components={blocks} enhanceProps={(at) => ({ locale, ...extra, ...blockPosition(at) })} />
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user