Files
AndreaSlopFotografie/docs/cms-integration.md
T
SluijsensandClaude Sonnet 5.5 bf21b6f690 Builds the markers, data block and stand-in host for the CMS host injection
The pages carry the CMS markers (data block, list regions, JSON-LD price,
inline price); PackagesProvider reads the host's data block after hydration
and asks the API only when there is none; the site address comes from the
block. A stand-in for the host (config/hostInjector.ts, --cms-data in the
preview server) and browser tests check the behaviour with different data.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 16:21:08 +01:00

11 KiB

CMS integration

The site talks to the SLP CMS host through its API. On the test host the CMS host serves the site itself, so every call is same-origin (/api/v1/*, CSP connect-src 'self', no CORS). Three things come from the CMS: the shoot packages, two banners and the contact form.

Shoot packages

Source: GET /api/v1/offerings. One list feeds the price cards on the home page and on the pages for each shoot type, the "welke shoot" choices of the contact form and the ?pakket= check, so they can never disagree.

  • Any number of packages. The cards are a wrapping flex row. On desktop (lg and up) every card is a third of the row (calc((100% - 2 * gap) / 3)) and every row is centred, so an incomplete last row (4, 5, 7, 8, 10 cards, ...) sits in the middle. There is no styling per number of cards. On phone and tablet the cards are one column; there is no swipe row.
  • Mapping (web/src/lib/offerings.ts, pure functions): slug is the package id (kept zwangerschap, newborn, gezin: they appear in ?pakket= and the form), title the name, the free price text is read as whole euros ("€ 175", "€ 1.250", "175,-"). A card with an unreadable price, no features or a bad slug is skipped. Order follows displayOrder. Empty description, priceNote and ctaLabel are accepted and left out of the card.
  • Where the data comes from, in order:
    1. At build time web/config/fetchOfferings.ts (the first step of pnpm build) asks OFFERINGS_URL (10 s timeout, 2 attempts) and writes the gitignored web/src/content/offerings.generated.json. The packages are baked into the prerendered HTML (search engines see the prices, no layout jump).
    2. Without OFFERINGS_URL, with a CMS that is down or with an unusable answer, the committed web/src/content/offerings.snapshot.json is used. The build never fails and never shows empty prices; the log says which source was used. Tests always use the snapshot.
    3. After hydration PackagesProvider (web/src/components/PackagesProvider/) asks the CMS once and replaces the baked list only if the answer differs. A network error, time-out (8 s), bad status or invalid answer keeps what was baked. A change in the CMS therefore shows at once; the nightly build only matters for search engines.
  • Featured package (the star in the CMS admin, field featured): the card gets a heidegroen rule along its top, a heidegroen border and a small "Uitgelicht" tab on the top edge (PriceCard). The tab is positioned on the border, so the cards of a row keep the same layout. Any number of cards may be featured.
  • Description, price note and button label (description, priceNote, ctaLabel) are optional in the CMS and the site does not use them: they are not shown and a card never depends on them (empty, null or absent all give the same card; covered by tests).
  • Scheduling in the CMS: the API only returns packages that are live at the moment of the request (switched on and inside their from/to dates), so the site shows them and nothing else. The baked list reflects the moment of the build; the live refresh after hydration corrects it for every visitor, and the nightly build corrects it for search engines. A package that goes live or expires between two builds is therefore right in the browser but can be stale in the HTML until the next build.
  • Keep the snapshot current when the real packages change (prices, features), because production builds use it (see "Hosting" below).

Banners (OfferingBanner)

Source: GET /api/v1/offerings/banner?position=top|bottom. No parameter means bottom; 204 means no active banner; an invalid value is 400. Answer fields: title (at most 100 characters), text (at most 300 for bottom, 120 for top), linkLabel, linkUrl (both or neither; https:// or a path on the site with one /) and position. Both banners may be active and visible at the same time.

Under the cards (bottom) Above the cards (top)
Component PriceBanner PriceTopBar
Look Light band, thin heidegroen top rule, section-heading title, ornament, sprig, deep-green link button Slim white bar, same hairline and top rule, one line: small capitals title, diamond, text, small underlined link
Required title title or text (title may be empty)
Mapping mapBanner mapTopBanner

Both follow the same rules as the packages: baked into the HTML at build time, replaced live after hydration, empty fields are hidden, an error or invalid answer keeps what was baked. A 204 hides that banner (the one deliberate exception to "keep what was baked"); the two banners are independent of each other. Neither banner is a package: not in the form choices, not in the package count.

Layout shift: a banner that was not active at the last build is not in the HTML. When it appears live, the content below it moves down by its height once (for the top bar, the cards move). Rebuilding with the banner active (the nightly test build does this) removes the shift. The same holds in reverse when a baked banner is switched off.

Contact form

GET /api/v1/contact-messages/token and POST /api/v1/contact-messages through the headless web/src/cms-client. The form is behind the switch contactForm.enabled in web/src/content/siteContent.ts (off means the "Binnenkort" gate and no request to the server). Details and the go-live conditions are in aidlc-docs/features/contact-form-cms/ and go-live-checklist.md. Friendly Captcha is off at go-live.

Hosting: the CMS host serves everything

Decision (Bryan, 2026-11-15): the hosting package has one entry per website. The CMS host (Kestrel) is that entry and serves the website itself (the prerendered pages), /admin and /api/v1/*. In production IIS (or the proxy) therefore passes all requests to the CMS host, not only /api/v1/*, and serves no static files or HTML cache of its own. This holds for the test host and for ASF production alike.

  • Test (ASF): nginx on the proxy Pi forwards everything for test.andreaslop.nl to the CMS host (web/deploy/nginx/test.andreaslop.nl.proxy.conf), which serves the site files and the API. Nothing to add.
  • Production: not in place yet. The generated web/deploy/iis/web.config and the FTP upload of static files (web/deploy/upload-production.sh) still describe the old idea of IIS serving the files. They have to change with the production hosting: IIS keeps only the redirects (www, HTTPS) and the pass-through to the CMS host, and the prerendered dist/ goes to the CMS host's prerendered-pages folder as on test. Security headers then come from the CMS host (as on test). This is part of the production hosting work, not of the packages feature. Until then production builds use the committed snapshot and the live calls fail safely (the baked list stays; the browser console shows a 404 for the API). Change generated server files only in web/config/serverConfig.ts and run pnpm server-config.
  • Host injection (built in the site; the host side is the CMS repo's work): the build leaves markers in the prerendered pages and the CMS host fills them from live data, so a CMS change is visible to search engines at once without a rebuild. Contract and plan: aidlc-docs/features/asf-cms-host-injection/plan.md; golden files for the list HTML: web/contract/host-injection/.
    • Markers: <!--CMS:DATA--> + <script type="application/json" id="cms-data"> (root document, every page), <!--CMS:OFFERINGS-HTML-->, <!--CMS:BANNER-TOP-HTML--> and <!--CMS:BANNER-BOTTOM-HTML--> regions (home page), <!--CMS:OFFER-JSON-LD slug="..."> before the ld+json block of the newborn, zwangerschap and gezin pages, and <span data-cms-price="slug"> in their price block.
    • In the page: CmsRegion renders the plain HTML between the markers (lib/cmsHtml.ts, styled by .cms-* rules in theme.ts) and React leaves it alone until hydration, so a host that wrote different data causes no hydration mismatch; after hydration the styled components take over. PackagesProvider reads the data block in the first render after hydration (hostCmsData); a block with "source":"build" is the baked one and counts as "no host data", so the page asks the API as before. The site address comes from siteUrl in the block (setSiteUrl in client.tsx), because the script files cannot be rewritten per host.
    • Tests: golden files (src/lib/cmsHtml.test.ts), a stand-in for the host (config/hostInjector.ts, also in the preview server as --cms-data=<json>) and browser tests with it (e2e/hostInjection.e2e.ts: HTML without JavaScript, hydration without errors, banners hidden on 204, JSON-LD price edited or removed, address changed and kept after navigation, unusable data, hostile text).

Environment and variables

Name Where Meaning
OFFERINGS_URL build env Site address that serves the API (for example https://test.andreaslop.nl). Unset gives the snapshot.
ASF_OFFERINGS_URL_TEST Gitea repo variable Value of OFFERINGS_URL for the test build. Set by SLS, not by feature sessions.
API_PROXY_TARGET dev env Forwards /api in pnpm dev to a CMS host.
VITE_SITE_URL build env Address the site presents itself under (canonical, og:*, JSON-LD, sitemap). Only the test build sets it (https://test.andreaslop.nl); unset gives https://andreaslop.nl.

The production artifact is built without OFFERINGS_URL on purpose: production must never carry the prices of the test CMS.