Hero uit het CMS, verschuivingsfix, productie alleen vanaf release-branch #18
@@ -172,7 +172,7 @@ jobs:
|
|||||||
build-production:
|
build-production:
|
||||||
needs: prepare
|
needs: prepare
|
||||||
runs-on: linux
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -348,10 +348,14 @@ jobs:
|
|||||||
# bewuste actie via workflow_dispatch met het "deploy_production"-vinkje
|
# bewuste actie via workflow_dispatch met het "deploy_production"-vinkje
|
||||||
# aangevinkt. Zo blijft de bestaande testdeploy-flow ongewijzigd en kan
|
# aangevinkt. Zo blijft de bestaande testdeploy-flow ongewijzigd en kan
|
||||||
# niemand per ongeluk productie deployen door simpelweg naar master te
|
# 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:
|
deploy-production:
|
||||||
needs: [build-production, test, lighthouse, config]
|
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
|
uses: ./.gitea/workflows/deploy.yaml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -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 |
|
||||||
@@ -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
|
## 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).
|
- [ ] 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).
|
- [ ] 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.
|
- [ ] Captcha provider decided (Gitea issue #14, `docs/captcha-providers.md` in the CMS repo). Captcha stays OFF in production until then.
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
|------|------|--------|--------|---------------------|---------------|
|
|------|------|--------|--------|---------------------|---------------|
|
||||||
| Feature | react-frontend | ✅ Complete | master | React frontend (SLP Software marketing site) | 2026-07-18 |
|
| 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 | 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 |
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -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`) |
|
||||||
@@ -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.
|
||||||
|
|
||||||
|
---
|
||||||
@@ -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 `<!--CMS:HERO-HTML-->`, `<!--CMS:HERO-PRELOAD-->`, `<!--CMS:DATA-->` 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.
|
||||||
@@ -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).
|
- `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`).
|
- 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)
|
- `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).
|
- 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-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.
|
- `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?
|
### 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:
|
Productie deployt **nooit** automatisch bij een push naar `master` — alleen via een expliciete, handmatige actie:
|
||||||
1. In Gitea, open de repository's **Actions** tab.
|
1. In Gitea, open de repository's **Actions** tab.
|
||||||
2. Selecteer de **Continuous Integration** workflow.
|
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/<naam>` (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.
|
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`.
|
5. Dit triggert naast de gebruikelijke `build`/`test`/`deploy-test` ook `build-production` en `deploy-production`.
|
||||||
|
|
||||||
|
|||||||
@@ -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 `<!--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.
|
||||||
|
|
||||||
|
## 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.
|
||||||
@@ -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
|
## 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.
|
- 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.
|
- `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.
|
- 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
|
## 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
|
// 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
|
// the components are moved over. Left out: tests and the privacy statement (its own feature). The Hero is
|
||||||
// statement (its own feature).
|
// checked too: its texts come from the CMS or from the language file (home.hero).
|
||||||
files: ['src/**/*.tsx'],
|
files: ['src/**/*.tsx'],
|
||||||
ignores: [
|
ignores: [
|
||||||
'**/Hero.tsx',
|
|
||||||
'**/Hero/**',
|
|
||||||
'**/hero/**',
|
|
||||||
'**/*.test.tsx',
|
'**/*.test.tsx',
|
||||||
'**/__tests__/**',
|
'**/__tests__/**',
|
||||||
'src/test/**',
|
'src/test/**',
|
||||||
|
|||||||
+20
@@ -45,6 +45,26 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<!--SLP:OFFERINGS-JSON-LD-->
|
<!--SLP:OFFERINGS-JSON-LD-->
|
||||||
|
<!-- The host may inject a crawler-readable packages list above #root (removed by main.tsx at start-up).
|
||||||
|
Take it out of the layout so that removing it does not shift the page (CLS). -->
|
||||||
|
<style>
|
||||||
|
#packages-static {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
margin: -1px;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0, 0, 0, 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->
|
||||||
|
<!--CMS:DATA-->
|
||||||
|
<script type="application/json" id="cms-data">
|
||||||
|
{}
|
||||||
|
</script>
|
||||||
<script src="/theme-init.js"></script>
|
<script src="/theme-init.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
+12
-1
@@ -20,7 +20,18 @@ await build({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { render } = await import(pathToFileURL(path.join(ssrDir, 'entry-server.mjs')).href);
|
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 html = await readFile(htmlPath, 'utf8');
|
||||||
const placeholder = '<div id="root"></div>';
|
const placeholder = '<div id="root"></div>';
|
||||||
|
|||||||
@@ -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([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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 ? '' : '<script type="application/json" id="cms-data"></script>';
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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(' ')}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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';
|
||||||
@@ -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<string, unknown>;
|
||||||
|
|
||||||
|
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<string, unknown>;
|
||||||
|
const cleanLabel = text(label);
|
||||||
|
if (cleanLabel !== '' && isSafeTarget(target)) {
|
||||||
|
buttons.push({ label: cleanLabel, target });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { title, lead: text(raw.lead) || null, buttons };
|
||||||
|
}
|
||||||
@@ -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 (`<script type="application/json" id="cms-data">`). */
|
||||||
|
export const CMS_DATA_ID = 'cms-data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the hero from the `#cms-data` block of the page. Returns null without a block, with a block that is not
|
||||||
|
* valid JSON, without a `hero` key (or `null`), or with a hero that is not usable: the site then keeps its baked hero.
|
||||||
|
*/
|
||||||
|
export function readHeroFromDocument(doc: Pick<Document, 'getElementById'>): CmsHero | null {
|
||||||
|
try {
|
||||||
|
const block = doc.getElementById(CMS_DATA_ID);
|
||||||
|
if (!block?.textContent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const data: unknown = JSON.parse(block.textContent);
|
||||||
|
if (data === null || typeof data !== 'object') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return parseHero((data as Record<string, unknown>).hero);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
const ANCHOR = /^#[A-Za-z0-9_-]+$/;
|
||||||
|
// Control characters, whitespace and backslashes never belong in a target.
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
|
const FORBIDDEN = /[\u0000- \u007f\\]/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a button target may be used as a link: exactly `#anchor`, a path of the own site (`/path`, not `//host`),
|
||||||
|
* or an absolute `https://` address with a host and no credentials. Everything else (`javascript:`, `http:`, `data:`,
|
||||||
|
* protocol-relative addresses, whitespace, backslashes) is refused. The CMS validates the same on saving; this is the
|
||||||
|
* second check at the point of use.
|
||||||
|
*/
|
||||||
|
export function isSafeTarget(target: unknown): target is string {
|
||||||
|
if (typeof target !== 'string' || target === '' || FORBIDDEN.test(target)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (target.startsWith('#')) {
|
||||||
|
return ANCHOR.test(target);
|
||||||
|
}
|
||||||
|
if (target.startsWith('/')) {
|
||||||
|
return !target.startsWith('//');
|
||||||
|
}
|
||||||
|
if (target.startsWith('https://')) {
|
||||||
|
try {
|
||||||
|
const url = new URL(target);
|
||||||
|
return url.protocol === 'https:' && url.hostname !== '' && url.username === '' && url.password === '';
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/** The lines of a title: split on line breaks, trimmed, empty lines dropped. */
|
||||||
|
export function titleLines(title: string): string[] {
|
||||||
|
return title
|
||||||
|
.split(/\r\n|\r|\n/)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter((line) => line !== '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The text for screen readers and search engines (the sr-only part of the `h1`): the brand prefix, a space and the
|
||||||
|
* title lines joined with single spaces. Without a prefix only the joined lines.
|
||||||
|
*/
|
||||||
|
export function headingFromLines(lines: readonly string[], prefix = ''): string {
|
||||||
|
const joined = lines.join(' ');
|
||||||
|
const start = prefix.trim();
|
||||||
|
return start === '' ? joined : `${start} ${joined}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/** A button of the hero: a label and a checked target (`#anchor`, `/path` or `https://...`). */
|
||||||
|
export interface CmsHeroButton {
|
||||||
|
label: string;
|
||||||
|
target: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hero as the CMS host writes it under `hero` in the `#cms-data` block (and as `GET /api/v1/hero` answers it),
|
||||||
|
* reduced to what a text-only site uses. Images (`slides`) and `tagline` are not part of the SLP Software hero and
|
||||||
|
* are left out here. Always the result of `parseHero`: texts are trimmed, buttons are checked.
|
||||||
|
*/
|
||||||
|
export interface CmsHero {
|
||||||
|
/** The title with its line breaks (`\n`), as entered in the CMS. */
|
||||||
|
title: string;
|
||||||
|
/** Optional paragraph under the title; null when empty. */
|
||||||
|
lead: string | null;
|
||||||
|
/** Zero to two buttons whose target passed `isSafeTarget`. */
|
||||||
|
buttons: CmsHeroButton[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { readHeroFromDocument } from './readHero';
|
||||||
|
import type { CmsHero } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CMS hero of this page load, or null (render the baked hero). The data block is in the first HTML, so it is
|
||||||
|
* read once, synchronously, in the first render: no flash of baked text before the CMS text. Without a document
|
||||||
|
* (the build-time prerender) it is always null, so the prerender keeps the baked hero.
|
||||||
|
*/
|
||||||
|
export function useCmsHero(): CmsHero | null {
|
||||||
|
const [hero] = useState<CmsHero | null>(() =>
|
||||||
|
typeof document === 'undefined' ? null : readHeroFromDocument(document),
|
||||||
|
);
|
||||||
|
return hero;
|
||||||
|
}
|
||||||
@@ -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 { 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
|
* Marks the place where the CMS host may write its hero HTML (`<!--CMS:HERO-HTML-->...<!--/CMS:HERO-HTML-->`). React
|
||||||
* code strip with the blinking caret. The nav sits directly above in the same colour.
|
* 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 (
|
return (
|
||||||
<section id="top" aria-labelledby="hero-heading" className="bg-brand text-on-brand">
|
<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">
|
<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
|
<h1
|
||||||
id="hero-heading"
|
id="hero-heading"
|
||||||
className="text-[clamp(56px,10.5vw,168px)] font-extrabold leading-[0.88] tracking-[-0.03em] [font-stretch:125%]"
|
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>
|
<span className="sr-only">{hero.heading}</span>
|
||||||
{heroContent.displayHeading.map((line, index) => (
|
{hero.lines.map((line, index) => (
|
||||||
<span
|
<span
|
||||||
key={line}
|
key={`${index}-${line}`}
|
||||||
className="block"
|
className="block"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
data-testid={`hero-line-${index}`}
|
data-testid={`hero-line-${index}`}
|
||||||
@@ -26,29 +51,25 @@ export function Hero() {
|
|||||||
))}
|
))}
|
||||||
</h1>
|
</h1>
|
||||||
<div className="mt-12 flex flex-wrap items-end justify-between gap-10 sm:mt-[72px] lg:gap-x-16">
|
<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>
|
{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">
|
<div className="flex flex-wrap gap-3">
|
||||||
<a
|
{hero.buttons.map((button, index) => (
|
||||||
href="#pakketten"
|
<HeroButtonLink
|
||||||
onClick={(event) => handleAnchorClick(event, '#pakketten')}
|
key={`${button.target}-${button.label}`}
|
||||||
className="bg-white px-[26px] py-[17px] text-base font-bold text-[#0e0d0d] no-underline transition-colors hover:bg-inv hover:text-white"
|
button={button}
|
||||||
>
|
className={BUTTON_CLASSES[Math.min(index, 1)]}
|
||||||
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>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{regionMarkers && <RegionMarker name="/CMS:HERO-HTML" />}
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-inv">
|
<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">
|
<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-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 className="caret ml-1.5 !bg-white" data-testid="hero-caret" />
|
||||||
</span>
|
</span>
|
||||||
<span className="text-sm text-[#a8a29c]">{heroContent.eyebrow}</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 {
|
export interface HeroContent {
|
||||||
|
/** Fixed text (not from the CMS): the small line in the code strip. */
|
||||||
eyebrow: string;
|
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;
|
heading: string;
|
||||||
/** Display headline of design B, one entry per line ("Websites," / "apps" / "& meer."). */
|
/** Display headline of design B, one entry per line ("Websites," / "apps" / "& meer."). */
|
||||||
displayHeading: string[];
|
displayHeading: string[];
|
||||||
lead: 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;
|
codeLine: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,12 +97,19 @@ export const navLinks: NavLink[] = [
|
|||||||
{ label: t('site.nav.cta'), href: '#contact', isCta: true },
|
{ 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 = {
|
export const heroContent: HeroContent = {
|
||||||
eyebrow: 'Web & .NET development',
|
eyebrow: t('home.hero.eyebrow'),
|
||||||
heading: 'SLP software: websites, apps & meer',
|
codePrompt: t('home.hero.codePrompt'),
|
||||||
displayHeading: ['Websites,', 'apps', '& meer.'],
|
headingPrefix: t('home.hero.headingPrefix'),
|
||||||
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.',
|
heading: t('home.hero.fallback.heading'),
|
||||||
codeLine: 'var website = slp.Bouw(uwIdee);',
|
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[] = [
|
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
|
* 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
|
* 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.
|
* same keys plus a language switch here; no component needs to change.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -36,6 +36,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"home": {
|
"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": {
|
"about": {
|
||||||
"photoAlt": "Bryan Slop, oprichter van SLP Software",
|
"photoAlt": "Bryan Slop, oprichter van SLP Software",
|
||||||
"heading": "Eén ontwikkelaar, korte lijnen",
|
"heading": "Eén ontwikkelaar, korte lijnen",
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
/* Metric-compatible stand-in for JetBrains Mono while it loads (both have an advance of 0.6em), so the code
|
||||||
|
line of the hero does not re-wrap and shift the page when the real font arrives (CLS). */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'JetBrains Mono Fallback';
|
||||||
|
src: local('Courier New'), local('Liberation Mono'), local('Cousine');
|
||||||
|
font-display: swap;
|
||||||
|
}
|
||||||
|
|
||||||
/* Theme tokens: variant (b | e) x mode (light | dark), selected by <html data-variant data-mode>
|
/* Theme tokens: variant (b | e) x mode (light | dark), selected by <html data-variant data-mode>
|
||||||
(set before first paint by public/theme-init.js and kept in sync by ThemeProvider).
|
(set before first paint by public/theme-init.js and kept in sync by ThemeProvider).
|
||||||
Semantic names stay the same so the Tailwind colors in tailwind.config.ts keep working.
|
Semantic names stay the same so the Tailwind colors in tailwind.config.ts keep working.
|
||||||
@@ -213,3 +221,35 @@ html {
|
|||||||
display: none;
|
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;
|
||||||
|
}
|
||||||
|
/* Brand prefix for screen readers and search engines ("SLP Software: "), not shown on screen */
|
||||||
|
.cms-hero-title-prefix {
|
||||||
|
@apply sr-only;
|
||||||
|
}
|
||||||
|
.cms-hero-title-lines {
|
||||||
|
@apply block;
|
||||||
|
}
|
||||||
|
.cms-hero-lead {
|
||||||
|
@apply mt-12 max-w-[48ch] text-[19px] leading-[1.55] sm:mt-[72px];
|
||||||
|
}
|
||||||
|
.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 { renderToString } from 'react-dom/server';
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { StaticLanding } from './StaticLanding';
|
import { StaticLanding } from './StaticLanding';
|
||||||
@@ -16,4 +17,32 @@ describe('StaticLanding (prerender)', () => {
|
|||||||
it('does not render the dynamic contact panel', () => {
|
it('does not render the dynamic contact panel', () => {
|
||||||
expect(html).not.toContain('data-testid="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
|
* app has loaded. That avoids hydration mismatches by construction (the real app reads
|
||||||
* localStorage/matchMedia while rendering; this tree must not). Only components without
|
* localStorage/matchMedia while rendering; this tree must not). Only components without
|
||||||
* window/storage/query dependencies are used here. Dynamic parts (packages, banner, contact
|
* 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() {
|
export function StaticLanding() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<main id="main">
|
<main id="main">
|
||||||
<Hero />
|
<Hero regionMarkers />
|
||||||
<AboutSection />
|
<AboutSection />
|
||||||
<section id="pakketten" aria-labelledby="pakketten-heading" className="bg-surface">
|
<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">
|
<div className="mx-auto max-w-[1280px] px-6 pb-24 pt-20 sm:px-8 md:pb-[136px] md:pt-32">
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import { resolve } from 'node:path';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
const root = resolve(__dirname, '../..');
|
||||||
|
const read = (file: string) => readFileSync(resolve(root, file), 'utf8');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guards against layout shifts (CLS) at start-up: the static packages list that the CMS host may inject above #root
|
||||||
|
* is removed by main.tsx, so it must not take any space, and the code line needs a metric-compatible font fallback.
|
||||||
|
*/
|
||||||
|
describe('layout stability at start-up', () => {
|
||||||
|
it('takes the injected #packages-static list out of the layout in index.html', () => {
|
||||||
|
const html = read('index.html');
|
||||||
|
const rule = html.match(/#packages-static\s*\{([^}]*)\}/);
|
||||||
|
expect(rule).not.toBeNull();
|
||||||
|
expect(rule?.[1]).toMatch(/position:\s*absolute/);
|
||||||
|
expect(rule?.[1]).toMatch(/clip:/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives the mono font a metric-compatible fallback', () => {
|
||||||
|
expect(read('src/index.css')).toMatch(/font-family:\s*'JetBrains Mono Fallback'/);
|
||||||
|
expect(read('tailwind.config.ts')).toMatch(/'JetBrains Mono',\s*'JetBrains Mono Fallback'/);
|
||||||
|
});
|
||||||
|
});
|
||||||
+20
-19
@@ -1,9 +1,13 @@
|
|||||||
|
import { useCmsHero } from '../../cms-client/hero';
|
||||||
import { heroContent } from '../../features/landing/data/content';
|
import { heroContent } from '../../features/landing/data/content';
|
||||||
import { t } from '../../i18n';
|
import { resolveHero } from '../../features/landing/data/resolveHero';
|
||||||
import { handleAnchorClick } from '../../utils/scrollToHash';
|
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() {
|
export function Era2026() {
|
||||||
|
const hero = resolveHero(useCmsHero());
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
aria-labelledby="hero-heading"
|
aria-labelledby="hero-heading"
|
||||||
@@ -19,27 +23,24 @@ export function Era2026() {
|
|||||||
id="hero-heading"
|
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%]"
|
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>
|
</h1>
|
||||||
<div className="mt-12 grid items-end gap-x-20 gap-y-10 md:mt-16 md:grid-cols-2">
|
<div className="mt-12 grid items-end gap-x-20 gap-y-10 md:mt-16 md:grid-cols-2">
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-8 mt-0 max-w-[46ch] text-[color:var(--e-body)]">{heroContent.lead}</p>
|
{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">
|
<div className="flex flex-wrap gap-3">
|
||||||
<a
|
{hero.buttons.map((button, index) => (
|
||||||
href="#pakketten"
|
<HeroButtonLink
|
||||||
onClick={(event) => handleAnchorClick(event, '#pakketten')}
|
key={`${button.target}-${button.label}`}
|
||||||
className="e-btn e-btn-solid"
|
button={button}
|
||||||
>
|
className={BUTTON_CLASSES[Math.min(index, 1)]}
|
||||||
{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>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p
|
<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)]"
|
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)]"
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ export default {
|
|||||||
// `[font-stretch:125%]` for the wide display type.
|
// `[font-stretch:125%]` for the wide display type.
|
||||||
sans: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
sans: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
||||||
display: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
display: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
||||||
mono: ['JetBrains Mono', 'monospace'],
|
mono: ['JetBrains Mono', 'JetBrains Mono Fallback', 'monospace'],
|
||||||
archivo: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
archivo: ['Archivo Variable', 'system-ui', 'sans-serif'],
|
||||||
},
|
},
|
||||||
borderRadius: {
|
borderRadius: {
|
||||||
|
|||||||
Reference in New Issue
Block a user