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/assumptions-to-check.md b/aidlc-docs/_shared/assumptions-to-check.md new file mode 100644 index 0000000..e1664c0 --- /dev/null +++ b/aidlc-docs/_shared/assumptions-to-check.md @@ -0,0 +1,16 @@ +# Assumptions to check (coordination, SLS session) + +Kept while the owner was away (2026-11-17). Each item: what I decided or assumed, why, what changes otherwise. The feature-specific lists live in each feature folder (CMS hero: 30 items, ASF hero: 10+, SLS hero: 9, media library: to follow). + +| # | Assumption or decision | Why | If the owner decides differently | +|---|---|---|---| +| 1 | Blanket go (owner, 2026-11-17): when everything is ready, PRs are made and merged to master, and pushes and deploys go to TEST. No production deploys, no `release/*` branches, no branch-protection changes except what is needed to merge. | Explicit message from the owner. | Stop merging; the branches stay as they are. | +| 2 | Merge order: CMS first (hero-module, then messages-badge, then admin-form-controls), then ASF hero, then SLS hero. A merge needs green PR checks. | The sites need the CMS host; the hero module is the largest change. | Another order only matters for conflicts. | +| 3 | The nightly ASF test build is removed (PR #20 merged, efd2aee). No periodic dependency audit replaces it ("niet nodig nu", owner). | The host injects CMS data per request (NFR-10); the nightly build overwrote test with master. | Add a small weekly audit workflow, or Dependabot/Renovate. | +| 4 | After a merge to master, the master run deploys to test only. I redeploy test from the feature branches only as long as they are not in master. | Production is manual and, for ASF and SLS, only from `release/*`. | n/a | +| 5 | The CMS test deploys of both sites go in ONE run (owner, 2026-11-17). | Fewer duplicate pipeline runs. | Split them again if a health check fails because of simultaneous restarts. | +| 6 | Sub-agents: the CMS session works serially because its own rule says sub-agents need the owner's direct request in its session. I use Sonnet sub-agents for my own SLS work. | Working agreement per session. | The owner tells the CMS session to use sub-agents for parallel streams. | +| 7 | The LCP of about 5 s on SLS (mobile) is not part of the hero feature. | Dominated by the app bundle; the hero is not the cause. | A separate performance feature. | +| 8 | Media library: starts after the merges, requirements and design only; nothing that moves data or changes public media addresses is built without the owner. | The owner chose "first the hero, then level 3"; data migrations and public addresses are risky. | Allow building up front. | +| 9 | Privacy statements (SLS concept, ASF page) are not touched; they keep their [OPEN] items (Sentry retention and DPA, Umami, EU transfer, processing agreement with MijnHostingPartner, captcha paragraph). | Owner kept them aside to review himself. | n/a | +| 10 | The CMS session briefly used a stale local master; the Contact module is on master (PR #15, b2cacfe). | Verified on origin/master. | n/a | 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/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..a3d09a4 --- /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**: COMPLETE for the test environment (2026-11-17). Hero from the CMS on test.slpsoftware.nl, CLS 0.00 and score 0.71 measured by the CMS session (Lighthouse mobile). Merge to master with the owner's blanket go (2026-11-17); no production release. Assumptions to check: `assumptions-and-open-questions.md`. +- **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/assumptions-and-open-questions.md b/aidlc-docs/features/hero-module/assumptions-and-open-questions.md new file mode 100644 index 0000000..a0bb6f3 --- /dev/null +++ b/aidlc-docs/features/hero-module/assumptions-and-open-questions.md @@ -0,0 +1,15 @@ +# Hero module, SLS side: assumptions and open points + +Written 2026-11-17 while the owner was away; to be checked by the owner. The CMS side has its own list (`aidlc-docs/features/hero-module/assumptions-and-open-questions.md` in the CMS repository, 30 items) and ASF has one too. + +| # | Question | Assumption made | If the owner chooses differently | Where | +|---|---|---|---|---| +| 1 | Screen-reader and search-engine heading | "SLP Software: Websites, apps & meer." (brand prefix + title lines joined by spaces; capital W and final full stop come from the seed title). The owner accepted this on 2026-11-16. | Another seed title, or a separate `heading` field in the CMS (model change). | `src/cms-client/hero/` (`headingFromLines`), `home.hero.headingPrefix` in `nl.json`, host setting `Hero:TitlePrefix` | +| 2 | Eyebrow ("Web & .NET development") and the code line | Fixed text in the language file, not from the CMS (decided 2026-11-16). | Make them CMS fields (tagline exists in the module). | `src/i18n/nl.json` (`home.hero`) | +| 3 | The text-only region for SLS needs host settings | `Hero:TextOnlyRegion` and `Hero:TitlePrefix` are set in the committed `appsettings.json` of the SLP host (`Api.SlpSoftware`); another host (master `Api`, local) needs `Hero__TextOnlyRegion=true`. | A per-site flag in the CMS or a separate marker. | CMS repo: `Api.SlpSoftware/appsettings.json` | +| 4 | Look of the injected hero before the app loads | The `cms-hero-*` classes in `src/index.css` approximate the React hero. The measured shift was caused by something else (the static packages list); CLS is 0.00 on test. | Rebuild the hero structure so the injected markup and the React hero are identical. | `src/index.css`, `docs/hero-integration.md` | +| 5 | The static packages list for crawlers | It stays in the HTML but is visually hidden (absolute, 1 px, clipped) so removing it at start-up no longer shifts the page. | Move the list elsewhere or inject it inside `#root`. | `index.html`, `src/test/layoutStability.test.ts` | +| 6 | Largest Contentful Paint | About 5 s on mobile Lighthouse (score 0.71). It is the lead paragraph and is dominated by the app bundle (CSS/JS under throttling), not by the hero. No fix is part of this feature. | A separate performance feature (smaller bundle, critical CSS, prerendered lead without JS). | `docs/hero-integration.md` | +| 7 | Hero without usable data | The baked hero stays (the host writes nothing); the site reads only the data block, not `GET /api/v1/hero` (decided with the CMS session). | Add a fetch fallback like ASF has. | `src/cms-client/hero/` | +| 8 | Production | SLS production is not touched. The production job only runs from a `release/*` branch (same rule as ASF). Before a production release the hero must be seeded in the production CMS (`scripts/Seed-Hero.ps1`, SLS seed `hero-sls.json`) and the production host needs the hero module and the settings from item 3. | n/a | `docs/hero-integration.md`, `aidlc-docs/_shared/joint-release-checklist.md` | +| 9 | Button targets | Only `#anchor`, `/path` or `https://…`, at most 2 buttons; others are skipped. | Allow `mailto:` or `tel:` (agree with the CMS side). | `src/cms-client/hero/` (`isSafeTarget`) | 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. 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`. diff --git a/docs/hero-integration.md b/docs/hero-integration.md new file mode 100644 index 0000000..6c44c69 --- /dev/null +++ b/docs/hero-integration.md @@ -0,0 +1,42 @@ +# 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 `` and `` followed by a baked ``. 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. + +## Layout shift (CLS) at start-up + +Measured on the test site (mobile, 4x CPU, slow 4G): CLS 0.35-0.40, one shift on `#root`. Cause: not the hero swap (that is about 1 px, CLS 0.0007) but the static packages list `#packages-static` that the host injects above `#root` (about 288 px high, visible) and that `main.tsx` removes at start-up, which moves the whole page up. A second, smaller shift (0.045, platform dependent) came from the code line of the hero re-wrapping when JetBrains Mono replaced the generic `monospace` fallback. + +Fixes: `index.html` takes `#packages-static` out of the layout (visually hidden, still in the HTML for crawlers); `src/index.css` defines `JetBrains Mono Fallback` (Courier New / Liberation Mono / Cousine, same 0.6em advance) in front of `monospace`. After the fix CLS is 0.000 locally (390, 412 and 1350 px wide). No change to the host markup is needed: the `cms-hero-*` region and the React hero take practically the same space. 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..496065f 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,26 @@ } + + + + + 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/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 (`'; + 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