Hero uit het CMS met ingebakken terugval: markers CMS:HERO-HTML, CMS:HERO-PRELOAD en CMS:DATA, hero-teksten naar nl.json, lint ook op Hero, tests en docs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:48:56 +01:00
co-authored by Claude Sonnet 5.5
parent 72dd381cf9
commit 27c5ecb80f
16 changed files with 400 additions and 62 deletions
@@ -0,0 +1,128 @@
import { render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it } from 'vitest';
import { Hero } from '../components/Hero';
import { Era2026 } from '../../../variants/e/Era2026';
import { heroContent } from '../data/content';
const cmsHero = {
display: 'single',
title: 'Sites,\nen apps\nvoor jou.',
tagline: null,
lead: 'Een andere lead uit het CMS.',
buttons: [
{ label: 'Eerste knop', target: '#pakketten' },
{ label: 'Tweede knop', target: 'https://example.com/plan' },
],
slides: [],
};
function setBlock(data: unknown) {
document.body.innerHTML = '<script type="application/json" id="cms-data"></script>';
document.getElementById('cms-data')!.textContent = typeof data === 'string' ? data : JSON.stringify(data);
}
afterEach(() => {
document.body.innerHTML = '';
});
describe('Hero with a CMS hero in the data block', () => {
it('shows the CMS title lines, lead and buttons', () => {
setBlock({ siteUrl: 'https://x', hero: cmsHero });
render(<Hero />);
expect(screen.getByTestId('hero-line-0')).toHaveTextContent('Sites,');
expect(screen.getByTestId('hero-line-1')).toHaveTextContent('en apps');
expect(screen.getByTestId('hero-line-2')).toHaveTextContent('voor jou.');
expect(screen.getByText('Een andere lead uit het CMS.')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Eerste knop' })).toHaveAttribute('href', '#pakketten');
const second = screen.getByRole('link', { name: 'Tweede knop' });
expect(second).toHaveAttribute('href', 'https://example.com/plan');
expect(second).toHaveAttribute('rel', 'noopener noreferrer');
expect(screen.queryByText(heroContent.lead)).toBeNull();
});
it('derives the screen-reader h1 from the title lines, with the brand prefix', () => {
setBlock({ hero: cmsHero });
render(<Hero />);
expect(
screen.getByRole('heading', { level: 1, name: 'SLP Software: Sites, en apps voor jou.' }),
).toBeInTheDocument();
});
it('gives the seed title exactly the heading that the contract expects', () => {
setBlock({ hero: { ...cmsHero, title: 'Websites,\napps\n& meer.' } });
render(<Hero />);
expect(
screen.getByRole('heading', { level: 1, name: 'SLP Software: Websites, apps & meer.' }),
).toBeInTheDocument();
});
it('leaves out the lead and the buttons when the CMS has none', () => {
setBlock({ hero: { ...cmsHero, lead: null, buttons: [] } });
render(<Hero />);
expect(screen.queryByRole('link')).toBeNull();
expect(screen.queryByText('Een andere lead uit het CMS.')).toBeNull();
});
it('does not render a button with an unsafe target', () => {
setBlock({
hero: {
...cmsHero,
buttons: [
{ label: 'Gevaarlijk', target: 'javascript:alert(1)' },
{ label: 'Veilig', target: '/pad' },
],
},
});
render(<Hero />);
expect(screen.queryByRole('link', { name: 'Gevaarlijk' })).toBeNull();
expect(screen.getByRole('link', { name: 'Veilig' })).toHaveAttribute('href', '/pad');
});
it('keeps the fixed texts: the small line and the code line', () => {
setBlock({ hero: cmsHero });
render(<Hero />);
expect(screen.getByText(heroContent.eyebrow)).toBeInTheDocument();
expect(screen.getByText(heroContent.codeLine, { exact: false })).toBeInTheDocument();
});
});
describe('Hero fallback (the baked hero)', () => {
it.each([
['no data block', null],
['the baked block', '{}'],
['hero null (204, not live, outside the schedule)', { hero: null }],
['invalid JSON', '{"hero":'],
['a hero without title', { hero: { title: '', buttons: [] } }],
])('shows the baked hero for %s', (_name, data) => {
if (data === null) {
document.body.innerHTML = '';
} else {
setBlock(data);
}
render(<Hero />);
expect(screen.getByRole('heading', { level: 1, name: heroContent.heading })).toBeInTheDocument();
expect(screen.getByText(heroContent.lead)).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Bekijk pakketten' })).toHaveAttribute('href', '#pakketten');
expect(screen.getByRole('link', { name: 'Plan een gesprek' })).toHaveAttribute('href', '#contact');
});
it('writes no region markers in the running app', () => {
const { container } = render(<Hero />);
expect(container.querySelector('[data-cms-marker]')).toBeNull();
});
});
describe('Era2026 hero', () => {
it('shows the CMS title and buttons, and falls back to the baked hero', () => {
setBlock({ hero: cmsHero });
const { unmount } = render(<Era2026 />);
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Sites, en apps voor jou.');
expect(screen.getByRole('link', { name: 'Eerste knop' })).toHaveAttribute('href', '#pakketten');
unmount();
document.body.innerHTML = '';
render(<Era2026 />);
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(heroContent.displayHeading.join(' '));
expect(screen.getByRole('link', { name: 'Bekijk pakketten' })).toHaveAttribute('href', '#pakketten');
});
});
+46 -25
View File
@@ -1,22 +1,47 @@
import { useCmsHero } from '../../../cms-client/hero';
import { heroContent } from '../data/content';
import { handleAnchorClick } from '../../../utils/scrollToHash';
import { resolveHero } from '../data/resolveHero';
import { HeroButtonLink } from './HeroButtonLink';
const BUTTON_CLASSES = [
'bg-white px-[26px] py-[17px] text-base font-bold text-[#0e0d0d] no-underline transition-colors hover:bg-inv hover:text-white',
'border-2 border-white px-6 py-[15px] text-base font-bold text-white no-underline transition-colors hover:bg-white hover:text-brand',
];
/**
* Hero of design B: display headline on the brand-red block, lead + two buttons, and the black
* code strip with the blinking caret. The nav sits directly above in the same colour.
* Marks the place where the CMS host may write its hero HTML (`<!--CMS:HERO-HTML-->...<!--/CMS:HERO-HTML-->`). React
* cannot write comments, so the build-time prerender renders these two elements and scripts/prerender.mjs turns them
* into the comments. Never rendered in the running app.
*/
export function Hero() {
function RegionMarker({ name }: { name: string }) {
return <i hidden data-cms-marker={name} />;
}
interface HeroProps {
/** Build-time prerender only: write the region markers around the part the CMS host may replace. */
regionMarkers?: boolean;
}
/**
* Hero of design B: display headline on the brand-red block, lead + buttons, and the black code strip with the
* blinking caret. The nav sits directly above in the same colour. The title, lead and buttons come from the CMS
* (data block `#cms-data`) when it delivered a hero, otherwise the baked texts are shown. The small line and the
* code line are fixed text of the site.
*/
export function Hero({ regionMarkers = false }: HeroProps) {
const hero = resolveHero(useCmsHero());
return (
<section id="top" aria-labelledby="hero-heading" className="bg-brand text-on-brand">
<div className="mx-auto max-w-[1280px] px-6 pb-16 pt-10 sm:px-8 sm:pb-24 sm:pt-16">
{regionMarkers && <RegionMarker name="CMS:HERO-HTML" />}
<h1
id="hero-heading"
className="text-[clamp(56px,10.5vw,168px)] font-extrabold leading-[0.88] tracking-[-0.03em] [font-stretch:125%]"
>
<span className="sr-only">{heroContent.heading}</span>
{heroContent.displayHeading.map((line, index) => (
<span className="sr-only">{hero.heading}</span>
{hero.lines.map((line, index) => (
<span
key={line}
key={`${index}-${line}`}
className="block"
aria-hidden="true"
data-testid={`hero-line-${index}`}
@@ -26,29 +51,25 @@ export function Hero() {
))}
</h1>
<div className="mt-12 flex flex-wrap items-end justify-between gap-10 sm:mt-[72px] lg:gap-x-16">
<p className="max-w-[48ch] text-[19px] leading-[1.55]">{heroContent.lead}</p>
<div className="flex flex-wrap gap-3">
<a
href="#pakketten"
onClick={(event) => handleAnchorClick(event, '#pakketten')}
className="bg-white px-[26px] py-[17px] text-base font-bold text-[#0e0d0d] no-underline transition-colors hover:bg-inv hover:text-white"
>
Bekijk pakketten
</a>
<a
href="#contact"
onClick={(event) => handleAnchorClick(event, '#contact')}
className="border-2 border-white px-6 py-[15px] text-base font-bold text-white no-underline transition-colors hover:bg-white hover:text-brand"
>
Plan een gesprek
</a>
</div>
{hero.lead && <p className="max-w-[48ch] text-[19px] leading-[1.55]">{hero.lead}</p>}
{hero.buttons.length > 0 && (
<div className="flex flex-wrap gap-3">
{hero.buttons.map((button, index) => (
<HeroButtonLink
key={`${button.target}-${button.label}`}
button={button}
className={BUTTON_CLASSES[Math.min(index, 1)]}
/>
))}
</div>
)}
</div>
{regionMarkers && <RegionMarker name="/CMS:HERO-HTML" />}
</div>
<div className="bg-inv">
<div className="font-mono mx-auto flex max-w-[1280px] flex-wrap items-center justify-between gap-x-8 gap-y-2 px-6 py-[22px] text-base sm:px-8">
<span className="text-white" aria-hidden="true">
<span className="text-[#a8a29c]">~/slp $</span> {heroContent.codeLine}
<span className="text-[#a8a29c]">{heroContent.codePrompt}</span> {heroContent.codeLine}
<span className="caret ml-1.5 !bg-white" data-testid="hero-caret" />
</span>
<span className="text-sm text-[#a8a29c]">{heroContent.eyebrow}</span>
@@ -0,0 +1,25 @@
import type { CmsHeroButton } from '../../../cms-client/hero';
import { handleAnchorClick } from '../../../utils/scrollToHash';
interface HeroButtonLinkProps {
button: CmsHeroButton;
className: string;
}
/**
* One hero button. The target was checked by the cms-client (`#anchor`, `/path` or `https://`); an in-page anchor scrolls
* smoothly (the app uses a hash router), a path or address is an ordinary link.
*/
export function HeroButtonLink({ button, className }: HeroButtonLinkProps) {
const external = button.target.startsWith('https://');
return (
<a
href={button.target}
onClick={(event) => handleAnchorClick(event, button.target)}
className={className}
{...(external ? { rel: 'noopener noreferrer' } : {})}
>
{button.label}
</a>
);
}
+20 -5
View File
@@ -21,11 +21,19 @@ export interface NavLink {
}
export interface HeroContent {
/** Fixed text (not from the CMS): the small line in the code strip. */
eyebrow: string;
/** Fixed text: the prompt before the code line. */
codePrompt: string;
/** Brand prefix of the screen-reader heading when the hero comes from the CMS. */
headingPrefix: string;
heading: string;
/** Display headline of design B, one entry per line ("Websites," / "apps" / "& meer."). */
displayHeading: string[];
lead: string;
/** Baked buttons (label + target), the fallback of the CMS buttons. */
buttons: { label: string; target: string }[];
/** Fixed text (not from the CMS). */
codeLine: string;
}
@@ -89,12 +97,19 @@ export const navLinks: NavLink[] = [
{ label: t('site.nav.cta'), href: '#contact', isCta: true },
];
/** The baked hero: the fallback when the CMS delivers nothing. Texts live in the language file (home.hero). */
export const heroContent: HeroContent = {
eyebrow: 'Web & .NET development',
heading: 'SLP software: websites, apps & meer',
displayHeading: ['Websites,', 'apps', '& meer.'],
lead: 'Bij SLP Software kun je terecht voor maatwerk oplossingen. Of het nou gaat om een website, cms of app: wij bouwen het allemaal. Voor ondernemers die geen verrassingen willen — niet in de code, niet op de factuur.',
codeLine: 'var website = slp.Bouw(uwIdee);',
eyebrow: t('home.hero.eyebrow'),
codePrompt: t('home.hero.codePrompt'),
headingPrefix: t('home.hero.headingPrefix'),
heading: t('home.hero.fallback.heading'),
displayHeading: [...tList('home.hero.fallback.lines')],
lead: t('home.hero.fallback.lead'),
buttons: [
{ label: t('home.hero.fallback.ctaPackages'), target: '#pakketten' },
{ label: t('home.hero.fallback.ctaContact'), target: '#contact' },
],
codeLine: t('home.hero.codeLine'),
};
export const packages: PackageCardData[] = [
+33
View File
@@ -0,0 +1,33 @@
import { headingFromLines, titleLines, type CmsHero, type CmsHeroButton } from '../../../cms-client/hero';
import { heroContent } from './content';
/** What the hero components show: from the CMS when it delivered a hero, otherwise the baked texts. */
export interface ResolvedHero {
/** Text for screen readers and search engines (the sr-only part of the h1). */
heading: string;
/** The visible title, one entry per line. */
lines: string[];
lead: string | null;
buttons: CmsHeroButton[];
fromCms: boolean;
}
export function resolveHero(cms: CmsHero | null): ResolvedHero {
if (cms === null) {
return {
heading: heroContent.heading,
lines: heroContent.displayHeading,
lead: heroContent.lead,
buttons: heroContent.buttons,
fromCms: false,
};
}
const lines = titleLines(cms.title);
return {
heading: headingFromLines(lines, heroContent.headingPrefix),
lines,
lead: cms.lead,
buttons: cms.buttons,
fromCms: true,
};
}
+1 -1
View File
@@ -2,7 +2,7 @@ import nlTexts from './nl.json';
/**
* Static website texts (Dutch). One JSON file per language (blocks: common, site, home, era); keys are typed so a missing or misspelled key
* fails the type check. Not included on purpose: the Hero (becomes a CMS module) and everything that
* fails the type check. Not included on purpose: the CMS hero (only its baked fallback and fixed lines are here, block home.hero) and everything that
* already comes from the CMS (packages, banners). A second language later = a second file (en.json) with the
* same keys plus a language switch here; no component needs to change.
*/
+13
View File
@@ -36,6 +36,19 @@
}
},
"home": {
"hero": {
"eyebrow": "Web & .NET development",
"codePrompt": "~/slp $",
"codeLine": "var website = slp.Bouw(uwIdee);",
"headingPrefix": "SLP Software:",
"fallback": {
"heading": "SLP software: websites, apps & meer",
"lines": ["Websites,", "apps", "& meer."],
"lead": "Bij SLP Software kun je terecht voor maatwerk oplossingen. Of het nou gaat om een website, cms of app: wij bouwen het allemaal. Voor ondernemers die geen verrassingen willen — niet in de code, niet op de factuur.",
"ctaPackages": "Bekijk pakketten",
"ctaContact": "Plan een gesprek"
}
},
"about": {
"photoAlt": "Bryan Slop, oprichter van SLP Software",
"heading": "Eén ontwikkelaar, korte lijnen",
+22
View File
@@ -213,3 +213,25 @@ html {
display: none;
}
}
/*
* Neutral hero HTML that the CMS host may write into the <!--CMS:HERO-HTML--> region of the first response
* (class names are the host's: cms-hero-*). Same look as the hero in Hero.tsx; React replaces it after loading.
*/
@layer components {
.cms-hero-title {
@apply text-[clamp(56px,10.5vw,168px)] font-extrabold leading-[0.88] tracking-[-0.03em] [font-stretch:125%];
}
.cms-hero-name {
@apply block;
}
.cms-hero-buttons {
@apply mt-12 flex flex-wrap gap-3 sm:mt-[72px];
}
.cms-hero-button {
@apply border-2 border-white px-6 py-[15px] text-base font-bold text-white no-underline transition-colors hover:bg-white hover:text-brand;
}
.cms-hero-button:first-child {
@apply bg-white px-[26px] py-[17px] text-[#0e0d0d] hover:bg-inv hover:text-white;
}
}
+29
View File
@@ -1,3 +1,4 @@
import { readFileSync } from 'node:fs';
import { renderToString } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import { StaticLanding } from './StaticLanding';
@@ -16,4 +17,32 @@ describe('StaticLanding (prerender)', () => {
it('does not render the dynamic contact panel', () => {
expect(html).not.toContain('data-testid="contact-panel"');
});
it('keeps the baked hero (fallback) between the two hero region placeholders', () => {
const open = html.indexOf('data-cms-marker="CMS:HERO-HTML"');
const close = html.indexOf('data-cms-marker="/CMS:HERO-HTML"');
expect(open).toBeGreaterThan(-1);
expect(close).toBeGreaterThan(open);
const region = html.slice(open, close);
expect(region).toContain('<h1');
expect(region).toContain(heroContent.lead);
expect(region).toContain('href="#pakketten"');
// The fixed code strip is outside the region: the host never replaces it.
expect(region).not.toContain(heroContent.codeLine);
expect(html.split('data-cms-marker=').length - 1).toBe(2);
});
});
describe('index.html template (host markers)', () => {
const template = readFileSync('index.html', 'utf8');
it('has the preload region and the data block marker for the CMS host', () => {
expect(template).toContain('<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->');
expect(template).toMatch(/<!--CMS:DATA-->\s*<script type="application\/json" id="cms-data">\s*\{\}\s*<\/script>/);
});
it('keeps the existing offerings markers', () => {
expect(template).toContain('<!--SLP:OFFERINGS-JSON-LD-->');
expect(template).toContain('<!--SLP:OFFERINGS-HTML-->');
});
});
+4 -2
View File
@@ -13,13 +13,15 @@ import { t } from '../i18n';
* app has loaded. That avoids hydration mismatches by construction (the real app reads
* localStorage/matchMedia while rendering; this tree must not). Only components without
* window/storage/query dependencies are used here. Dynamic parts (packages, banner, contact
* form) are NOT prerendered; the packages come from the CMS host markers in index.html.
* form) are NOT prerendered; the packages come from the CMS host markers in index.html. The hero is the baked
* fallback, between the markers <!--CMS:HERO-HTML--> that scripts/prerender.mjs writes: the host replaces the
* region when the CMS has a hero (docs/hero-integration.md).
*/
export function StaticLanding() {
return (
<>
<main id="main">
<Hero />
<Hero regionMarkers />
<AboutSection />
<section id="pakketten" aria-labelledby="pakketten-heading" className="bg-surface">
<div className="mx-auto max-w-[1280px] px-6 pb-24 pt-20 sm:px-8 md:pb-[136px] md:pt-32">
+22 -21
View File
@@ -1,9 +1,13 @@
import { useCmsHero } from '../../cms-client/hero';
import { heroContent } from '../../features/landing/data/content';
import { t } from '../../i18n';
import { handleAnchorClick } from '../../utils/scrollToHash';
import { resolveHero } from '../../features/landing/data/resolveHero';
import { HeroButtonLink } from '../../features/landing/components/HeroButtonLink';
/** 2026: modern hero with the live headline and the blinking code line. */
const BUTTON_CLASSES = ['e-btn e-btn-solid', 'e-btn e-btn-outline'];
/** 2026: modern hero with the live headline and the blinking code line. Title, lead and buttons come from the CMS, with the baked hero as fallback. */
export function Era2026() {
const hero = resolveHero(useCmsHero());
return (
<section
aria-labelledby="hero-heading"
@@ -19,27 +23,24 @@ export function Era2026() {
id="hero-heading"
className="m-0 max-w-[11ch] text-[clamp(44px,8vw,116px)] font-extrabold leading-[0.92] tracking-[-0.035em] [font-stretch:118%]"
>
{heroContent.displayHeading.join(' ')}
{hero.lines.join(' ')}
</h1>
<div className="mt-12 grid items-end gap-x-20 gap-y-10 md:mt-16 md:grid-cols-2">
<div>
<p className="mb-8 mt-0 max-w-[46ch] text-[color:var(--e-body)]">{heroContent.lead}</p>
<div className="flex flex-wrap gap-3">
<a
href="#pakketten"
onClick={(event) => handleAnchorClick(event, '#pakketten')}
className="e-btn e-btn-solid"
>
{t('era.e2026.ctaPackages')}
</a>
<a
href="#contact"
onClick={(event) => handleAnchorClick(event, '#contact')}
className="e-btn e-btn-outline"
>
{t('era.e2026.ctaContact')}
</a>
</div>
{hero.lead && (
<p className="mb-8 mt-0 max-w-[46ch] text-[color:var(--e-body)]">{hero.lead}</p>
)}
{hero.buttons.length > 0 && (
<div className="flex flex-wrap gap-3">
{hero.buttons.map((button, index) => (
<HeroButtonLink
key={`${button.target}-${button.label}`}
button={button}
className={BUTTON_CLASSES[Math.min(index, 1)]}
/>
))}
</div>
)}
</div>
<p
className="m-0 overflow-x-auto whitespace-nowrap rounded-md border border-[color:var(--e-line-strong)] px-5 py-[18px] font-mono text-[15px] text-[color:var(--e-body)]"