From 0f3b7e0a2ee9a0736dd37efc3e818683a03553de Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Mon, 16 Nov 2026 16:48:55 +0100 Subject: [PATCH 1/8] Feature hero-module: status, requirements-verwijzing en audit (SLS-kant) Co-Authored-By: Claude Sonnet 5.5 --- aidlc-docs/active-features.md | 1 + .../features/hero-module/aidlc-state.md | 39 +++++++++++++++++++ aidlc-docs/features/hero-module/audit.md | 9 +++++ .../features/hero-module/requirements.md | 16 ++++++++ 4 files changed, 65 insertions(+) create mode 100644 aidlc-docs/features/hero-module/aidlc-state.md create mode 100644 aidlc-docs/features/hero-module/audit.md create mode 100644 aidlc-docs/features/hero-module/requirements.md diff --git a/aidlc-docs/active-features.md b/aidlc-docs/active-features.md index e598001..0b7e28f 100644 --- a/aidlc-docs/active-features.md +++ b/aidlc-docs/active-features.md @@ -4,3 +4,4 @@ |------|------|--------|--------|---------------------|---------------| | Feature | react-frontend | ✅ Complete | master | React frontend (SLP Software marketing site) | 2026-07-18 | | Feature | redesign-modern-timetravel | 🔵 Inception | feature/redesign-modern-timetravel | Theme system, Nav, all landing sections, Contact form (+ CMS/API for form endpoint) | 2026-11-09 | +| Feature | hero-module | 🟢 Construction (test) | feature/hero-module | Hero from the CMS (markers, data block, fallback), CI production condition | 2026-11-16 | diff --git a/aidlc-docs/features/hero-module/aidlc-state.md b/aidlc-docs/features/hero-module/aidlc-state.md new file mode 100644 index 0000000..60d7fb5 --- /dev/null +++ b/aidlc-docs/features/hero-module/aidlc-state.md @@ -0,0 +1,39 @@ +# AI-DLC State Tracking + +## Project Information +- **Feature Name**: Hero module, SLS side (hero from the CMS, baked hero as fallback) +- **Feature Slug**: hero-module +- **Project Type**: Brownfield +- **Start Date**: 2026-11-16 +- **Current Stage**: Construction, built for the TEST environment only (no production deploy, no merge to master without the user's go) +- **Branch**: feature/hero-module + +## Workspace State +- **Existing Code**: Yes +- **Workspace Root**: K:\Development\SlpSoftware\Projects\SlpSoftware + +## Code Location Rules +- **Application Code**: Workspace root (NEVER in aidlc-docs/) +- **Feature Documentation**: aidlc-docs/features/hero-module/ only + +## Language Configuration +- **Documentation Language**: English +- **Conversation Language**: Dutch + +## Extension Configuration +| Extension | Enabled | Decided At | +|---|---|---| +| Security Baseline | Yes | Requirements Analysis | +| Property-Based Testing | Partial (pure functions: title derivation, target validation) | Requirements Analysis | + +## Operations Configuration +- **Include Operations Phase**: No, as separate stages. Covered by the joint release checklist (`aidlc-docs/_shared/joint-release-checklist.md`). + +## Requirements +The requirements and the site contract are owned by the CMS repository (branch `feature/hero-module`, K:\Development\Projects\SlpModularCms-contact-forms): +- `aidlc-docs/features/hero-module/inception/requirements/requirements.md` +- `aidlc-docs/features/hero-module/inception/requirements/site-contract-agreed-with-asf.md` +- `aidlc-docs/features/hero-module/inception/requirements/hero-comparison.md` +- `docs/hero-module.md` + +See `requirements.md` in this folder for the SLS decisions. diff --git a/aidlc-docs/features/hero-module/audit.md b/aidlc-docs/features/hero-module/audit.md new file mode 100644 index 0000000..1606375 --- /dev/null +++ b/aidlc-docs/features/hero-module/audit.md @@ -0,0 +1,9 @@ +# Audit Log: hero-module (SLS) + +## SLS integration started +**Timestamp**: 2026-11-16 +**User Input**: "Doe de SLS-kant van de Hero-module integratie. Alles alleen voor TEST; GEEN productie-deploys, geen merge naar master, geen dispatches van workflows." (relayed by the main session, with Bryan's SLS decisions: title with line breaks, lead, two buttons, no tagline or slides; eyebrow and code line fixed text) +**AI Response**: Branch `feature/hero-module` from origin/master. Read the CMS contract, golden files and host renderer. Built markers, `#cms-data` reader in `src/cms-client/hero`, Hero rendering with fallback, derived screen-reader h1, target validation, tests; aligned the production deploy condition with ASF; documented in `docs/hero-integration.md`. +**Context**: Construction, test only. + +--- diff --git a/aidlc-docs/features/hero-module/requirements.md b/aidlc-docs/features/hero-module/requirements.md new file mode 100644 index 0000000..07f9dd9 --- /dev/null +++ b/aidlc-docs/features/hero-module/requirements.md @@ -0,0 +1,16 @@ +# Requirements: Hero module, SLS side + +Source of truth: the CMS repository (see `aidlc-state.md`). This file holds only what is specific to SLP Software. + +## Decisions of Bryan for SLS (2026-11-16) +- The hero comes from the CMS: title (one field, line breaks: "Websites,\napps\n& meer."), lead, two buttons (label + target). No tagline, no slides. +- Fixed text in the site (`src/i18n/nl.json`, block `home.hero`): the small line "Web & .NET development" and the code line "var website = slp.Bouw(uwIdee);". +- Screen-reader/search-engine h1: `home.hero.headingPrefix` ("SLP Software:") + the title lines joined with a single space. Seed result: "SLP Software: Websites, apps & meer." +- The baked hero (`heroContent`, `Hero.tsx`, `Era2026.tsx`, `StaticLanding.tsx`) is the fallback when the CMS delivers nothing (no block, no hero, not live, outside the schedule, invalid data). +- Changes in the CMS are live (NFR-10): the host writes the data block into every page response (60 s cache). + +## Contract points used +Markers ``, ``, `` and key `hero` in `#cms-data`. Button targets: `#anchor`, `/path`, `https://`. Details and open points: `docs/hero-integration.md`. + +## Pipeline +`deploy-production` (and its build) only run for `workflow_dispatch` with `deploy_production == 'true'` on a `release/*` branch, like ASF. From 02f3d9e931214494598f329be7943baf4384cab4 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Mon, 16 Nov 2026 16:48:55 +0100 Subject: [PATCH 2/8] CI: productie-deploy en productie-build alleen bij workflow_dispatch met deploy_production op een release/*-branch (gelijk aan ASF); documentatie bijgewerkt Co-Authored-By: Claude Sonnet 5.5 --- .gitea/workflows/continuous_integration.yaml | 10 +++++++--- aidlc-docs/_shared/joint-release-checklist.md | 2 +- .../operations/deployment/deployment-instructions.md | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/continuous_integration.yaml b/.gitea/workflows/continuous_integration.yaml index 520fe13..e4b56a3 100644 --- a/.gitea/workflows/continuous_integration.yaml +++ b/.gitea/workflows/continuous_integration.yaml @@ -172,7 +172,7 @@ jobs: build-production: needs: prepare runs-on: linux - if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' + if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' && startsWith(github.ref, 'refs/heads/release/') steps: - uses: actions/checkout@v4 @@ -348,10 +348,14 @@ jobs: # bewuste actie via workflow_dispatch met het "deploy_production"-vinkje # aangevinkt. Zo blijft de bestaande testdeploy-flow ongewijzigd en kan # niemand per ongeluk productie deployen door simpelweg naar master te - # pushen of de workflow handmatig te starten zonder dat vinkje. + # pushen of de workflow handmatig te starten zonder dat vinkje. Het vinkje + # werkt bovendien alleen op een branch die met release/ begint. deploy-production: needs: [build-production, test, lighthouse, config] - if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' + # Alleen vanaf een release/*-branch (zoals de ASF-site): een dispatch met het + # vinkje op master of een feature-branch doet voor productie niets. Een push + # deployt nooit naar productie. + if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' && startsWith(github.ref, 'refs/heads/release/') uses: ./.gitea/workflows/deploy.yaml secrets: inherit with: diff --git a/aidlc-docs/_shared/joint-release-checklist.md b/aidlc-docs/_shared/joint-release-checklist.md index a0a5a8f..6df415e 100644 --- a/aidlc-docs/_shared/joint-release-checklist.md +++ b/aidlc-docs/_shared/joint-release-checklist.md @@ -6,7 +6,7 @@ Status on 2026-11-16: everything is merged to master and runs on TEST only. No p ## Before the release moment - [ ] ASF IIS publish pipeline exists (own feature: self-contained win-x64 publish, FTP upload, web.config, the CMS host as the single entry for the website; open hosting questions are answered by trying it with ASF). -- [ ] Hero module feature decided (release with or without it). +- [ ] Hero module feature decided (release with or without it). SLS side: `docs/hero-integration.md`; production needs the seeded hero in the production CMS, the CMS host with the hero module, and the LCP check on the site afterwards. - [ ] Privacy statement and static texts reviewed by the owner (kept aside until now). - [ ] Captcha provider decided (Gitea issue #14, `docs/captcha-providers.md` in the CMS repo). Captcha stays OFF in production until then. diff --git a/aidlc-docs/features/react-frontend/operations/deployment/deployment-instructions.md b/aidlc-docs/features/react-frontend/operations/deployment/deployment-instructions.md index 2ac71d4..1ae5044 100644 --- a/aidlc-docs/features/react-frontend/operations/deployment/deployment-instructions.md +++ b/aidlc-docs/features/react-frontend/operations/deployment/deployment-instructions.md @@ -11,10 +11,10 @@ Sinds deze stap wordt er automatisch gedeployed naar een **testomgeving**: een R - `continuous_integration.yaml` — getriggerd door `pull_request` (build/test/lint-gate, ongeacht branch), `push` naar `master` (build/test/lint-gate + `deploy-test`), en handmatig via `workflow_dispatch` (met een optioneel `deploy_production`-vinkje). - Heeft bovenaan een `env:`-blok met alle aanpasbare waarden op één plek: `NODE_VERSION`, `PNPM_VERSION`, `ARTIFACT_NAME` (`dist`), `ARTIFACT_NAME_PRODUCTION` (`dist-production`), `ARTIFACT_PATH` (`dist/`), `DEPLOY_ENVIRONMENT` (`test`), `DEPLOY_PATH` (gelezen uit de Gitea repository variable `DEPLOY_PATH_TEST`, zie hieronder — bewust geen hardcoded pad), `DEPLOY_ENVIRONMENT_PRODUCTION` (`production`) en `DEPLOY_PATH_PRODUCTION` (gelezen uit de variable `DEPLOY_PATH_PRODUCTION`). - `prepare` → `build` (test-bundel, `VITE_APP_ENV=test`) → `test` (lint + unit tests) - - `build-production` draait ernaast, alléén als `deploy_production` is aangevinkt bij een handmatige `workflow_dispatch`-run. Dit is een aparte build (niet hetzelfde artifact als `build`) omdat `VITE_APP_ENV` een build-time Vite-variabele is: één bundel kan niet tegelijk als `test` én `production` getagd zijn in Sentry/analytics. + - `build-production` draait ernaast, alléén als `deploy_production` is aangevinkt bij een handmatige `workflow_dispatch`-run **op een `release/*`-branch**. Dit is een aparte build (niet hetzelfde artifact als `build`) omdat `VITE_APP_ENV` een build-time Vite-variabele is: één bundel kan niet tegelijk als `test` én `production` getagd zijn in Sentry/analytics. - Een losse `config`-job zet alle `env`-waarden (test én productie) om in job-outputs (zie hieronder waarom dat nodig is). - `deploy-test` (bij `workflow_dispatch` of een push naar `master`) roept `deploy.yaml` aan met `artifact_name`/`environment`/`deploy_path` afkomstig van `needs.config.outputs.*` (dus indirect uit het `env:`-blok). - - `deploy-production` (alléén bij `workflow_dispatch` mét `deploy_production: true`) roept `deploy.yaml` op dezelfde manier aan, maar met de productie-artifact/omgeving/pad. Draait **nooit** automatisch bij een push naar `master`. + - `deploy-production` (alléén bij `workflow_dispatch` mét `deploy_production: true` **én een ref die met `refs/heads/release/` begint**, zoals de ASF-site; een dispatch vanaf `master` of een feature-branch doet voor productie niets) roept `deploy.yaml` op dezelfde manier aan, maar met de productie-artifact/omgeving/pad. Draait **nooit** automatisch bij een push naar `master`. - `deploy.yaml` — download de artifact (naam/lokaal pad = `inputs.artifact_name`) en upload de inhoud via een `scp`-commando (met `sshpass` voor het wachtwoord) in een gewone shell-stap naar de opgegeven `deploy_path` op de host uit de meegegeven secrets. Deze workflow is omgeving-agnostisch (test/productie) en hoefde niet gewijzigd te worden. ### Waarom `sshpass`/`scp` in een shell-stap in plaats van de `appleboy/scp-action` Docker-action? @@ -77,7 +77,7 @@ Merge een pull request naar `master` — de `deploy-test` job draait dan automat Productie deployt **nooit** automatisch bij een push naar `master` — alleen via een expliciete, handmatige actie: 1. In Gitea, open de repository's **Actions** tab. 2. Selecteer de **Continuous Integration** workflow. -3. Klik **Run workflow**, kies de gewenste branch/ref (meestal `master`). +3. Klik **Run workflow**, kies een branch `release/` (bijv. `release/2026-11-20`, gemaakt vanaf `master`). Vanaf een andere branch (ook `master`) gebeurt er voor productie niets, ook niet met het vinkje. 4. Vink **`deploy_production`** aan voordat je de run start. 5. Dit triggert naast de gebruikelijke `build`/`test`/`deploy-test` ook `build-production` en `deploy-production`. From 72dd381cf908d0d139ee50f27732b134a7b29858 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Mon, 16 Nov 2026 16:48:55 +0100 Subject: [PATCH 3/8] cms-client: hero uit het datablok #cms-data (parseHero, doelcontrole, titelregels en afgeleide kop, useCmsHero) met tests Co-Authored-By: Claude Sonnet 5.5 --- .../hero/__tests__/parseHero.test.ts | 66 +++++++++++++++++++ .../hero/__tests__/readHero.test.ts | 33 ++++++++++ src/cms-client/hero/__tests__/target.test.ts | 64 ++++++++++++++++++ src/cms-client/hero/__tests__/title.test.ts | 47 +++++++++++++ src/cms-client/hero/index.ts | 6 ++ src/cms-client/hero/parseHero.ts | 41 ++++++++++++ src/cms-client/hero/readHero.ts | 25 +++++++ src/cms-client/hero/target.ts | 31 +++++++++ src/cms-client/hero/title.ts | 17 +++++ src/cms-client/hero/types.ts | 19 ++++++ src/cms-client/hero/useCmsHero.ts | 15 +++++ 11 files changed, 364 insertions(+) create mode 100644 src/cms-client/hero/__tests__/parseHero.test.ts create mode 100644 src/cms-client/hero/__tests__/readHero.test.ts create mode 100644 src/cms-client/hero/__tests__/target.test.ts create mode 100644 src/cms-client/hero/__tests__/title.test.ts create mode 100644 src/cms-client/hero/index.ts create mode 100644 src/cms-client/hero/parseHero.ts create mode 100644 src/cms-client/hero/readHero.ts create mode 100644 src/cms-client/hero/target.ts create mode 100644 src/cms-client/hero/title.ts create mode 100644 src/cms-client/hero/types.ts create mode 100644 src/cms-client/hero/useCmsHero.ts diff --git a/src/cms-client/hero/__tests__/parseHero.test.ts b/src/cms-client/hero/__tests__/parseHero.test.ts new file mode 100644 index 0000000..48363e3 --- /dev/null +++ b/src/cms-client/hero/__tests__/parseHero.test.ts @@ -0,0 +1,66 @@ +import { describe, expect, it } from 'vitest'; +import { parseHero } from '../parseHero'; + +// The seed of the SLP Software hero in the CMS (scripts/hero-sls.json of the CMS repository). +const seed = { + display: 'single', + title: 'Websites,\napps\n& meer.', + tagline: null, + lead: 'Bij SLP Software kun je terecht.', + buttons: [ + { label: 'Bekijk pakketten', target: '#pakketten' }, + { label: 'Plan een gesprek', target: '#contact' }, + ], + slides: [], +}; + +describe('parseHero', () => { + it('reads the seed hero of the CMS', () => { + expect(parseHero(seed)).toEqual({ + title: 'Websites,\napps\n& meer.', + lead: 'Bij SLP Software kun je terecht.', + buttons: seed.buttons, + }); + }); + + it('returns null (baked hero) without a usable hero', () => { + for (const value of [null, undefined, 'x', 5, [], {}, { title: '' }, { title: ' \n ' }, { title: 7 }]) { + expect(parseHero(value)).toBeNull(); + } + }); + + it('ignores tagline and slides: a text-only site', () => { + const hero = parseHero({ ...seed, tagline: 'Label', slides: [{ id: 'x' }] }); + expect(hero).not.toBeNull(); + expect(hero).not.toHaveProperty('tagline'); + expect(hero).not.toHaveProperty('slides'); + }); + + it('turns an empty lead into null and trims texts', () => { + expect(parseHero({ ...seed, lead: ' ' })?.lead).toBeNull(); + expect(parseHero({ ...seed, lead: null })?.lead).toBeNull(); + expect(parseHero({ ...seed, lead: ' Hallo ' })?.lead).toBe('Hallo'); + }); + + it('skips buttons with an unsafe target or an empty label, never repairs them', () => { + const hero = parseHero({ + ...seed, + buttons: [ + { label: 'Slecht', target: 'javascript:alert(1)' }, + { label: ' ', target: '#contact' }, + { label: 'Goed', target: '/over' }, + null, + 'x', + ], + }); + expect(hero?.buttons).toEqual([{ label: 'Goed', target: '/over' }]); + }); + + it('keeps at most two buttons and accepts zero or a missing list', () => { + const three = [1, 2, 3].map((n) => ({ label: `B${n}`, target: `#b${n}` })); + expect(parseHero({ ...seed, buttons: three })?.buttons).toHaveLength(2); + expect(parseHero({ ...seed, buttons: [] })?.buttons).toEqual([]); + expect(parseHero({ title: 'x' })?.buttons).toEqual([]); + expect(parseHero({ title: 'x', buttons: 'nope' })?.buttons).toEqual([]); + }); +}); diff --git a/src/cms-client/hero/__tests__/readHero.test.ts b/src/cms-client/hero/__tests__/readHero.test.ts new file mode 100644 index 0000000..cabc0cb --- /dev/null +++ b/src/cms-client/hero/__tests__/readHero.test.ts @@ -0,0 +1,33 @@ +import { afterEach, describe, expect, it } from 'vitest'; +import { readHeroFromDocument } from '../readHero'; + +function setBlock(text: string | null) { + document.body.innerHTML = text === null ? '' : ''; + if (text !== null) { + document.getElementById('cms-data')!.textContent = text; + } +} + +afterEach(() => { + document.body.innerHTML = ''; +}); + +describe('readHeroFromDocument', () => { + it('reads the hero key of the data block', () => { + setBlock(JSON.stringify({ siteUrl: 'https://x', offerings: [], hero: { title: 'A\nB', buttons: [] } })); + expect(readHeroFromDocument(document)).toEqual({ title: 'A\nB', lead: null, buttons: [] }); + }); + + it.each([ + ['no block', null], + ['an empty block', ''], + ['the baked block', '{}'], + ['hero null', '{"hero":null}'], + ['invalid JSON', '{"hero": '], + ['a block that is not an object', '"hero"'], + ['a hero without title', '{"hero":{"title":" "}}'], + ])('returns null for %s (baked hero stays)', (_name, text) => { + setBlock(text); + expect(readHeroFromDocument(document)).toBeNull(); + }); +}); diff --git a/src/cms-client/hero/__tests__/target.test.ts b/src/cms-client/hero/__tests__/target.test.ts new file mode 100644 index 0000000..47b8e85 --- /dev/null +++ b/src/cms-client/hero/__tests__/target.test.ts @@ -0,0 +1,64 @@ +import fc from 'fast-check'; +import { describe, expect, it } from 'vitest'; +import { isSafeTarget } from '../target'; + +describe('isSafeTarget', () => { + it.each([ + '#pakketten', + '#contact', + '#a-b_c1', + '/', + '/over-mij', + '/a?b=1&c=2', + 'https://example.com', + 'https://example.com/x?y=1#z', + ])('accepts %s', (target) => { + expect(isSafeTarget(target)).toBe(true); + }); + + it.each([ + '', + '#', + '# x', + '#a b', + '#a.b', + '//evil.example/x', + '/\\evil', + '/a b', + 'javascript:alert(1)', + 'JAVASCRIPT:alert(1)', + 'data:text/html,x', + 'http://example.com', + 'https://', + 'https://user:pw@example.com', + 'https://user@example.com', + 'ftp://example.com', + 'mailto:a@b.nl', + 'pakketten', + 'https://exa mple.com', + '/a\nb', + ])('refuses %j', (target) => { + expect(isSafeTarget(target)).toBe(false); + }); + + it('refuses anything that is not a string', () => { + for (const value of [null, undefined, 1, {}, [], true]) { + expect(isSafeTarget(value)).toBe(false); + } + }); + + it('property: whatever is accepted has one of the three allowed forms and no unsafe characters', () => { + fc.assert( + fc.property(fc.string(), (value) => { + if (!isSafeTarget(value)) return true; + const allowedForm = + /^#[A-Za-z0-9_-]+$/.test(value) || + (value.startsWith('/') && !value.startsWith('//')) || + value.startsWith('https://'); + // eslint-disable-next-line no-control-regex + return allowedForm && !/[\u0000- \u007f\\]/.test(value); + }), + { numRuns: 500 }, + ); + }); +}); diff --git a/src/cms-client/hero/__tests__/title.test.ts b/src/cms-client/hero/__tests__/title.test.ts new file mode 100644 index 0000000..e74176e --- /dev/null +++ b/src/cms-client/hero/__tests__/title.test.ts @@ -0,0 +1,47 @@ +import fc from 'fast-check'; +import { describe, expect, it } from 'vitest'; +import { headingFromLines, titleLines } from '../title'; + +describe('titleLines', () => { + it('splits on line breaks and trims', () => { + expect(titleLines('Websites,\napps\n& meer.')).toEqual(['Websites,', 'apps', '& meer.']); + expect(titleLines(' a \r\n b\r c ')).toEqual(['a', 'b', 'c']); + }); + + it('drops empty lines', () => { + expect(titleLines('\n\na\n\n b \n')).toEqual(['a', 'b']); + expect(titleLines(' \n ')).toEqual([]); + }); + + it('property: no line is empty, has line breaks or has outer spaces', () => { + fc.assert( + fc.property(fc.string(), (title) => + titleLines(title).every( + (line) => line !== '' && line === line.trim() && !/[\r\n]/.test(line), + ), + ), + ); + }); +}); + +describe('headingFromLines (screen-reader and search-engine heading)', () => { + it('puts the brand prefix before the lines joined with single spaces (the seed title)', () => { + expect(headingFromLines(['Websites,', 'apps', '& meer.'], 'SLP Software:')).toBe( + 'SLP Software: Websites, apps & meer.', + ); + }); + + it('works without a prefix and with a single line', () => { + expect(headingFromLines(['Alleen'])).toBe('Alleen'); + expect(headingFromLines(['Alleen'], ' ')).toBe('Alleen'); + }); + + it('property: the heading is the prefix, a space and the lines joined by spaces', () => { + fc.assert( + fc.property( + fc.array(fc.string({ minLength: 1 }), { minLength: 1 }), + (lines) => headingFromLines(lines, 'SLP Software:') === `SLP Software: ${lines.join(' ')}`, + ), + ); + }); +}); diff --git a/src/cms-client/hero/index.ts b/src/cms-client/hero/index.ts new file mode 100644 index 0000000..d9e57b2 --- /dev/null +++ b/src/cms-client/hero/index.ts @@ -0,0 +1,6 @@ +export { CMS_DATA_ID, readHeroFromDocument } from './readHero'; +export { parseHero } from './parseHero'; +export { isSafeTarget } from './target'; +export { headingFromLines, titleLines } from './title'; +export { useCmsHero } from './useCmsHero'; +export type { CmsHero, CmsHeroButton } from './types'; diff --git a/src/cms-client/hero/parseHero.ts b/src/cms-client/hero/parseHero.ts new file mode 100644 index 0000000..49c76b8 --- /dev/null +++ b/src/cms-client/hero/parseHero.ts @@ -0,0 +1,41 @@ +import { isSafeTarget } from './target'; +import { titleLines } from './title'; +import type { CmsHero, CmsHeroButton } from './types'; + +const MAX_BUTTONS = 2; + +function text(value: unknown): string { + return typeof value === 'string' ? value.trim() : ''; +} + +/** + * Turns the untrusted `hero` value of the data block (or the API) into a `CmsHero`, or null when nothing usable is + * there: no object, no title, or a title without any text. Fail-open: null means "show the baked hero". Buttons with + * an empty label or an unsafe target are skipped (never repaired); at most two are kept. + */ +export function parseHero(value: unknown): CmsHero | null { + if (value === null || typeof value !== 'object' || Array.isArray(value)) { + return null; + } + const raw = value as Record; + + const title = typeof raw.title === 'string' ? titleLines(raw.title).join('\n') : ''; + if (title === '') { + return null; + } + + const buttons: CmsHeroButton[] = []; + if (Array.isArray(raw.buttons)) { + for (const item of raw.buttons) { + if (buttons.length >= MAX_BUTTONS) break; + if (item === null || typeof item !== 'object') continue; + const { label, target } = item as Record; + const cleanLabel = text(label); + if (cleanLabel !== '' && isSafeTarget(target)) { + buttons.push({ label: cleanLabel, target }); + } + } + } + + return { title, lead: text(raw.lead) || null, buttons }; +} diff --git a/src/cms-client/hero/readHero.ts b/src/cms-client/hero/readHero.ts new file mode 100644 index 0000000..1195139 --- /dev/null +++ b/src/cms-client/hero/readHero.ts @@ -0,0 +1,25 @@ +import { parseHero } from './parseHero'; +import type { CmsHero } from './types'; + +/** Id of the data block the CMS host writes into the page (``. The build (`scripts/prerender.mjs`) writes `` ... `` 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. diff --git a/docs/translations.md b/docs/translations.md index 2f1d5aa..ff8eae1 100644 --- a/docs/translations.md +++ b/docs/translations.md @@ -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 diff --git a/eslint.config.js b/eslint.config.js index cf8e1d8..0855257 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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/**', diff --git a/index.html b/index.html index 7f5af33..c8a2937 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,11 @@ } + + + diff --git a/scripts/prerender.mjs b/scripts/prerender.mjs index bf865e2..3ec436b 100644 --- a/scripts/prerender.mjs +++ b/scripts/prerender.mjs @@ -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 +// placeholders that become here. Without a host they are +// plain comments and nothing changes for the visitor. +const markerPattern = /]*data-cms-marker="([^"]+)"[^>]*><\/i>/g; +const rendered = render(); +const markup = rendered.replace(markerPattern, (_all, name) => ``); +const expectedMarkers = ['', '']; +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 = '
'; diff --git a/src/features/landing/__tests__/HeroCms.test.tsx b/src/features/landing/__tests__/HeroCms.test.tsx new file mode 100644 index 0000000..187d511 --- /dev/null +++ b/src/features/landing/__tests__/HeroCms.test.tsx @@ -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 = ''; + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(heroContent.displayHeading.join(' ')); + expect(screen.getByRole('link', { name: 'Bekijk pakketten' })).toHaveAttribute('href', '#pakketten'); + }); +}); diff --git a/src/features/landing/components/Hero.tsx b/src/features/landing/components/Hero.tsx index ad9a53c..c563f5b 100644 --- a/src/features/landing/components/Hero.tsx +++ b/src/features/landing/components/Hero.tsx @@ -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 (`...`). 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