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:
@@ -0,0 +1,36 @@
|
||||
# Hero from the CMS (SLP Software site)
|
||||
|
||||
The title, lead and buttons of the hero come from the CMS. The baked hero stays as the fallback. Contract and CMS side: the CMS repository, `aidlc-docs/features/hero-module/inception/requirements/site-contract-agreed-with-asf.md` and `docs/hero-module.md`.
|
||||
|
||||
## What is CMS content and what is fixed
|
||||
|
||||
| Part | Source |
|
||||
|---|---|
|
||||
| Title (one field, a new line is a line break) | CMS, key `hero.title` |
|
||||
| Lead | CMS, `hero.lead` (no lead: no paragraph) |
|
||||
| Two buttons (label + target) | CMS, `hero.buttons` (none: no buttons) |
|
||||
| Tagline, slides, display | Not used by this site (ignored) |
|
||||
| Small line "Web & .NET development", code line, prompt | Fixed text, `src/i18n/nl.json`, block `home.hero` |
|
||||
| Screen-reader and search-engine `h1` | Derived: `home.hero.headingPrefix` ("SLP Software:") + a space + the title lines joined with single spaces |
|
||||
| Baked fallback (title lines, lead, buttons, heading) | `src/i18n/nl.json`, `home.hero.fallback`, via `heroContent` in `src/features/landing/data/content.ts` |
|
||||
|
||||
Seed (`hero-sls.json`): title "Websites,\napps\n& meer." gives the heading "SLP Software: Websites, apps & meer." The baked heading stays "SLP software: websites, apps & meer" (unchanged, so the prerender is unchanged); the two differ only in capitals and the final full stop.
|
||||
|
||||
## How it works
|
||||
|
||||
1. `index.html` has `<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->` and `<!--CMS:DATA-->` followed by a baked `<script type="application/json" id="cms-data">{}</script>`. The build (`scripts/prerender.mjs`) writes `<!--CMS:HERO-HTML-->` ... `<!--/CMS:HERO-HTML-->` around the baked title, lead and buttons in the prerendered `#root` (the code strip is outside the region). The host replaces the regions and the data block per request (60 s cache); nothing else about the page changes. Without a host, or when the host answers 204, the markers are plain comments.
|
||||
2. At start-up the app reads `#cms-data` once (`src/cms-client/hero`, `useCmsHero`), synchronously in the first render, so there is no flash of baked text. `parseHero` checks everything: no usable title, invalid JSON or no `hero` key gives the baked hero. Buttons with an empty label or a target that is not `#anchor`, `/path` or `https://...` are skipped (`isSafeTarget`), at most two are used.
|
||||
3. `Hero.tsx` (design B) and `Era2026.tsx` (time travel 2026) render the same content: the first button solid, the second outline.
|
||||
4. A change in the CMS is visible on the next page load (host cache 60 s, direct invalidation in the host).
|
||||
|
||||
## Without a CMS hero (fallback)
|
||||
|
||||
No data block, `hero: null` (204: no hero, not live, outside the schedule), or invalid data: the baked hero. The prerender always uses the baked hero.
|
||||
|
||||
## Baseline
|
||||
|
||||
The only change in the prerendered text compared with the build before this feature is the extra marker comments and the empty data block (`pnpm baseline:check` keeps `CMS:` comments and JSON blocks, so the saved baseline has to be saved again once: `pnpm baseline:save`; checked line by line that only those lines differ).
|
||||
|
||||
## Open points for the CMS host
|
||||
|
||||
See the report of this feature: the host renders the hero region only when the hero has a usable slide, and it writes picture/`h1` HTML without the lead. For this text-only site the region therefore stays the baked hero and the visitor gets the CMS text from the data block after the app has loaded. The site already styles the host's `cms-hero-*` classes (`src/index.css`) for the day the host can write a text-only region.
|
||||
@@ -31,12 +31,12 @@ A key is a dotted path: the namespace, then the section, then the element, for e
|
||||
|
||||
## What is deliberately not in the language files
|
||||
|
||||
- The Hero (component and hero data): it becomes a CMS module.
|
||||
- The title, lead and buttons of the Hero: they come from the CMS (data block `#cms-data`, see `docs/hero-integration.md`). The baked fallback texts of the Hero and its fixed lines (small line, code line, brand prefix of the heading) are in the language file, block `home.hero`.
|
||||
- Everything that comes from the CMS: packages, banners, and so on.
|
||||
- `src/cms-client`: it is a movable package and has its own messages (`messages.nl.ts`); it may not import from the app.
|
||||
- The privacy statement: it is its own feature and has its own text.
|
||||
|
||||
ESLint knows these exceptions: `react/jsx-no-literals` and a rule for text attributes (`aria-label`, `aria-description`, `alt`, `title`, `placeholder`, `label`) warn about a text typed straight into JSX in `src/**/*.tsx`, except in the Hero, tests and the privacy statement. Single technical signs (`/`, `|`, `-`, `:`, and so on), whitespace and numbers are allowed. They are warnings for now; they become errors when the move is done.
|
||||
ESLint knows these exceptions: `react/jsx-no-literals` and a rule for text attributes (`aria-label`, `aria-description`, `alt`, `title`, `placeholder`, `label`) warn about a text typed straight into JSX in `src/**/*.tsx`, except in tests and the privacy statement. Single technical signs (`/`, `|`, `-`, `:`, and so on), whitespace and numbers are allowed. They are warnings for now; they become errors when the move is done.
|
||||
|
||||
## Adding a second language
|
||||
|
||||
|
||||
+2
-5
@@ -26,13 +26,10 @@ export default tseslint.config(
|
||||
},
|
||||
{
|
||||
// Texts of the site live in the language files (src/i18n), not in the JSX. A warning for now while
|
||||
// the components are moved over. Left out: the Hero (becomes a CMS module), tests and the privacy
|
||||
// statement (its own feature).
|
||||
// the components are moved over. Left out: tests and the privacy statement (its own feature). The Hero is
|
||||
// checked too: its texts come from the CMS or from the language file (home.hero).
|
||||
files: ['src/**/*.tsx'],
|
||||
ignores: [
|
||||
'**/Hero.tsx',
|
||||
'**/Hero/**',
|
||||
'**/hero/**',
|
||||
'**/*.test.tsx',
|
||||
'**/__tests__/**',
|
||||
'src/test/**',
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
}
|
||||
</script>
|
||||
<!--SLP:OFFERINGS-JSON-LD-->
|
||||
<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->
|
||||
<!--CMS:DATA-->
|
||||
<script type="application/json" id="cms-data">
|
||||
{}
|
||||
</script>
|
||||
<script src="/theme-init.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
+12
-1
@@ -20,7 +20,18 @@ await build({
|
||||
});
|
||||
|
||||
const { render } = await import(pathToFileURL(path.join(ssrDir, 'entry-server.mjs')).href);
|
||||
const markup = render();
|
||||
// The hero marks the region the CMS host may replace; React cannot write comments, so the component renders
|
||||
// <i data-cms-marker="CMS:HERO-HTML"> placeholders that become <!--CMS:HERO-HTML--> here. Without a host they are
|
||||
// plain comments and nothing changes for the visitor.
|
||||
const markerPattern = /<i\s[^>]*data-cms-marker="([^"]+)"[^>]*><\/i>/g;
|
||||
const rendered = render();
|
||||
const markup = rendered.replace(markerPattern, (_all, name) => `<!--${name}-->`);
|
||||
const expectedMarkers = ['<!--CMS:HERO-HTML-->', '<!--/CMS:HERO-HTML-->'];
|
||||
for (const marker of expectedMarkers) {
|
||||
if (markup.split(marker).length !== 2 || /data-cms-marker/.test(markup)) {
|
||||
throw new Error(`prerender: expected exactly one ${marker} in the static landing`);
|
||||
}
|
||||
}
|
||||
|
||||
const html = await readFile(htmlPath, 'utf8');
|
||||
const placeholder = '<div id="root"></div>';
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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[] = [
|
||||
|
||||
@@ -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
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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-->');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
@@ -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)]"
|
||||
|
||||
Reference in New Issue
Block a user