Hero from the CMS: markers HERO-HTML and HERO-PRELOAD, hero key in the data block, picture per ratio, baked fallback

The prerendered hero is plain HTML between the markers (first photo, h1, buttons), the slider takes over after hydration with the hero of the host block, the API or the build. The head preload is added to the finished HTML. Hero texts move into nl.json. The stand-in host and the e2e tests cover the hero.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:48:00 +01:00
co-authored by Claude Sonnet 5.5
parent 13f78c48cd
commit ad0b114828
31 changed files with 863 additions and 134 deletions
+7
View File
@@ -43,6 +43,13 @@ describe('parseCmsData', () => {
});
});
it('passes the hero answer on unchecked', () => {
expect(
parseCmsData(JSON.stringify({ hero: { title: 'T' } }))?.hero,
).toEqual({ title: 'T' });
expect(parseCmsData('{}')?.hero).toBeUndefined();
});
it('falls back to production for an address that is not an origin', () => {
expect(
parseCmsData(JSON.stringify({ siteUrl: 'ftp://x' }))?.siteUrl,
+4
View File
@@ -25,6 +25,9 @@ export interface CmsData {
offerings?: unknown;
// undefined: not in the block; null: no active banner
banners?: { top?: unknown; bottom?: unknown };
// The answer of GET /api/v1/hero, not yet checked (lib/hero mapHero);
// undefined: not in the block
hero?: unknown;
}
const isObject = (value: unknown): value is Record<string, unknown> =>
@@ -50,6 +53,7 @@ export function parseCmsData(text: string | null | undefined): CmsData | null {
: undefined,
offerings: Array.isArray(raw.offerings) ? raw.offerings : undefined,
banners,
hero: raw.hero,
};
}
+11 -6
View File
@@ -19,9 +19,14 @@ const PORTRAIT = '(orientation: portrait)';
const LANDSCAPE = '(orientation: landscape)';
const SIZES = '100vw';
const srcsetOf = (variants: HeroImageVariant[], ratio: string): string =>
// The srcset of one ratio and format ("tall" or "wide"; WebP unless said)
export const variantSrcset = (
variants: HeroImageVariant[],
ratio: string,
type = 'image/webp',
): string =>
variants
.filter((v) => v.ratio === ratio && v.type === 'image/webp')
.filter((v) => v.ratio === ratio && v.type === type)
.sort((a, b) => a.width - b.width)
.map((v) => `${escapeHtml(v.url)} ${v.width}w`)
.join(', ');
@@ -37,8 +42,8 @@ const focusStyle = (slide: HeroSlide): string => {
function pictureHtml(slide: HeroSlide): string {
const { image } = slide;
const tall = srcsetOf(image.variants, 'tall');
const wide = srcsetOf(image.variants, 'wide');
const tall = variantSrcset(image.variants, 'tall');
const wide = variantSrcset(image.variants, 'wide');
const source = tall
? `<source media="${PORTRAIT}" srcset="${tall}" sizes="${SIZES}" type="image/webp">`
: '';
@@ -83,8 +88,8 @@ export function heroHtml(hero: HeroData | null): string {
export function heroPreloadHtml(hero: HeroData | null): string {
if (!hero) return '';
const { image } = hero.slides[0];
const tall = srcsetOf(image.variants, 'tall');
const wide = srcsetOf(image.variants, 'wide');
const tall = variantSrcset(image.variants, 'tall');
const wide = variantSrcset(image.variants, 'wide');
const link = (target: string, media: string): string =>
`<link rel="preload" as="image" ${target}` +
`${media ? ` media="${media}"` : ''} fetchpriority="high">`;