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 -1
View File
@@ -155,7 +155,13 @@ describe.each(priorityPages)('prioriteitsfoto van %s', (path) => {
for (const node of body.querySelectorAll('noscript')) node.remove();
const prioritized = [
...body.querySelectorAll('img[fetchpriority="high"][src]'),
].filter((image) => !image.closest('picture'));
// The hero photo sits in a <picture> but has no <source> for the
// baked page, so its preload is the plain one (config/heroPreload)
].filter(
(image) =>
!image.closest('picture') ||
image.classList.contains('cms-hero-image'),
);
expect(prioritized.length).toBeGreaterThan(0);
for (const image of prioritized) {
const links = preloads(document).filter(
+85
View File
@@ -74,6 +74,8 @@ describe('markers in de gebouwde pagina', () => {
'OFFERINGS-HTML',
'BANNER-TOP-HTML',
'BANNER-BOTTOM-HTML',
'HERO-HTML',
'HERO-PRELOAD',
]) {
expect(home.split(`<!--CMS:${marker}-->`)).toHaveLength(2);
expect(home.split(`<!--/CMS:${marker}-->`)).toHaveLength(2);
@@ -337,3 +339,86 @@ describe('zonder host die injecteert', () => {
expect(messages).toEqual([]);
});
});
const hostHero = (extra: Record<string, unknown> = {}) => ({
display: 'slideshow',
title: 'Nieuwe titel',
tagline: 'Nieuw label',
buttons: [{ label: 'Boek nu', target: '#contact' }],
slides: ['een', 'twee'].map((name) => ({
id: name,
alt: `Alt ${name}`,
decorative: false,
image: {
width: 100,
height: 80,
focus: { x: 0.25, y: 0.75 },
src: '/favicon.png',
variants: [],
},
})),
...extra,
});
describe('de hero van de host', () => {
it('schrijft de eerste foto, de titel en de preload in de HTML', async () => {
inject({ offerings: FIVE, banners: NO_BANNERS, hero: hostHero() });
const home = await html('/');
const region = home.slice(
home.indexOf('<!--CMS:HERO-HTML-->'),
home.indexOf('<!--/CMS:HERO-HTML-->'),
);
expect(region).toContain('Nieuwe titel');
expect(region).toContain('alt="Alt een"');
expect(region).not.toContain('Alt twee');
expect(region).toContain('style="object-position:25% 75%"');
expect(region).toContain('href="#contact"');
expect(home).toContain(
'<!--CMS:HERO-PRELOAD--><link rel="preload" as="image" href="/favicon.png" fetchpriority="high"><!--/CMS:HERO-PRELOAD-->',
);
});
it('toont na hydratatie de slides van de host, zonder API-verzoek', async () => {
inject({ offerings: FIVE, banners: NO_BANNERS, hero: hostHero() });
const requested: string[] = [];
const { page, messages } = await openPage(server.origin + '/', {
prepare: async (p) => {
p.on('request', (request) => {
if (request.url().includes('/api/v1/hero')) {
requested.push(request.url());
}
});
},
});
await waitForHydration(page);
await eventually(() =>
page.locator('[aria-roledescription="carousel"] h1').textContent(),
).toContain('Nieuwe titel');
expect(
await page
.locator('[aria-roledescription="carousel"] img')
.first()
.getAttribute('alt'),
).toBe('Alt een');
expect(requested).toEqual([]);
expect(messages).toEqual([]);
});
it('laat de gebakken hero staan als de data niet bruikbaar is', async () => {
inject({
offerings: FIVE,
banners: NO_BANNERS,
hero: hostHero({ slides: [] }),
});
const home = await html('/');
// The data block still holds what the host sent; the region keeps the
// baked hero
const region = home.slice(
home.indexOf('<!--CMS:HERO-HTML-->'),
home.indexOf('<!--/CMS:HERO-HTML-->'),
);
expect(region).not.toContain('Nieuwe titel');
expect(region).toContain('Andrea Slop');
expect(home).toContain('<!--CMS:HERO-PRELOAD--><link');
});
});
+2 -1
View File
@@ -128,7 +128,8 @@ describe.each(widths)('zonder JavaScript op %i px', (width) => {
.count(),
).resolves.toBe(0);
}
const hero = page.locator('[aria-roledescription="carousel"]');
// De platte hero (tussen de CMS-markers), geen carrousel
const hero = page.locator('[data-cms-region="HERO-HTML"]');
await expect(
hero.locator('img:visible').count(),
).resolves.toBeGreaterThan(0);