Hero from the CMS: markers HERO-HTML and HERO-PRELOAD, hero key in the data block, picture per ratio, baked fallback

The prerendered hero is plain HTML between the markers (first photo, h1, buttons), the slider takes over after hydration with the hero of the host block, the API or the build. The head preload is added to the finished HTML. Hero texts move into nl.json. The stand-in host and the e2e tests cover the hero.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:48:00 +01:00
co-authored by Claude Sonnet 5.5
parent 13f78c48cd
commit ad0b114828
31 changed files with 863 additions and 134 deletions
+14 -5
View File
@@ -9,6 +9,8 @@
// matches that code.
import { bannerHtml, offeringsHtml } from '../src/lib/cmsHtml.ts';
import { scriptJson } from '../src/lib/cmsData.ts';
import { mapHero } from '../src/lib/hero.ts';
import { heroHtml, heroPreloadHtml } from '../src/lib/heroHtml.ts';
import { formatPrice } from '../src/lib/formatPrice.ts';
import { mapBanner, mapOfferings, mapTopBanner } from '../src/lib/offerings.ts';
@@ -16,6 +18,8 @@ export interface LiveData {
// The answers as the public API gives them
offerings: unknown;
banners: { top: unknown; bottom: unknown };
// The answer of GET /api/v1/hero; absent or unusable leaves the baked hero
hero?: unknown;
}
export interface InjectOptions {
@@ -33,7 +37,7 @@ const jsonLd = (value: unknown) =>
.replace(/&/g, '\\u0026');
const REGION =
/<!--CMS:(OFFERINGS-HTML|BANNER-TOP-HTML|BANNER-BOTTOM-HTML)-->[\s\S]*?<!--\/CMS:\1-->/g;
/<!--CMS:(OFFERINGS-HTML|BANNER-TOP-HTML|BANNER-BOTTOM-HTML|HERO-HTML|HERO-PRELOAD)-->[\s\S]*?<!--\/CMS:\1-->/g;
const DATA_BLOCK =
/<!--CMS:DATA-->(?:<script type="application\/json" id="cms-data">[\s\S]*?<\/script>)?/g;
const OFFER_JSON_LD =
@@ -64,19 +68,23 @@ export function injectCms(html: string, options: InjectOptions): string {
const { data } = options;
const mapped = mapOfferings(data.offerings);
const packages = mapped ? mapped.packages : [];
const hero = mapHero(data.hero);
const prices: Price = new Map(packages.map((pkg) => [pkg.id, pkg.price]));
const regions: Record<string, string> = {
'OFFERINGS-HTML': offeringsHtml(packages),
'BANNER-TOP-HTML': bannerHtml(mapTopBanner(data.banners.top)),
'BANNER-BOTTOM-HTML': bannerHtml(mapBanner(data.banners.bottom)),
'HERO-HTML': heroHtml(hero),
'HERO-PRELOAD': heroPreloadHtml(hero),
};
const siteUrl = options.publicBaseUrl ?? options.authoredBaseUrl;
let out = html
.replace(
REGION,
(_match, name: string) =>
`<!--CMS:${name}-->${regions[name]}<!--/CMS:${name}-->`,
.replace(REGION, (match, name: string) =>
// No usable hero: the baked one stays (fail open)
name.startsWith('HERO') && !hero
? match
: `<!--CMS:${name}-->${regions[name]}<!--/CMS:${name}-->`,
)
.replace(
DATA_BLOCK,
@@ -86,6 +94,7 @@ export function injectCms(html: string, options: InjectOptions): string {
...(siteUrl ? { siteUrl } : {}),
offerings: data.offerings,
banners: data.banners,
...(data.hero === undefined ? {} : { hero: data.hero }),
})}</script>`,
)
.replace(OFFER_JSON_LD, (match, slug: string, json: string) => {