Adds the hero contract: golden files for the picture and the preload links, mapping and seed
Model B (wide 3:2 and tall 4:5 variants, focus point), agreed with the CMS session. Pure functions mapHero, heroHtml and heroPreloadHtml, golden files in web/contract/host-injection/hero with a README, and a seed with a first focus estimate per photo. No site change yet. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# Hero contract (ASF site and CMS host)
|
||||
|
||||
Golden files for the hero regions that the CMS host fills, model B (decided 2026-11-16): the host cuts a `wide` (3:2) and a `tall` (4:5) variant per photo around the focus point, and the site uses `<picture>`. Same idea as the packages (`../README.md`): for every `NAME.input.json` the host's template must give exactly `NAME.expected.html` (between `<!--CMS:HERO-HTML-->` and `<!--/CMS:HERO-HTML-->`) and `NAME.expected-preload.html` (between `<!--CMS:HERO-PRELOAD-->` and `<!--/CMS:HERO-PRELOAD-->` in the head). The file ends with one newline that is not part of the HTML. The ASF repo tests its own implementation (`src/lib/hero.ts`, `src/lib/heroHtml.ts`) against the same files; to change the contract, change the code and run `UPDATE_GOLDEN=1 pnpm test src/lib/heroHtml.test.ts`, then send the new files to the CMS session. The ASF commit is in `git log -1 -- web/contract/host-injection/hero`.
|
||||
|
||||
## Input
|
||||
|
||||
The answer of `GET /api/v1/hero` (an object). A 204 (no hero) is `null`: the output is empty and the baked hero stays.
|
||||
|
||||
## Rules
|
||||
|
||||
1. Usable hero: an object with a non-empty `title` (trimmed) and at least one usable slide; otherwise both outputs are empty strings (fail open: the baked page stays).
|
||||
2. A slide is kept when: `id` is non-empty; `image.src` is a path of our host (starts with one `/`, not `//`, no backslash); `image.width` and `image.height` are whole numbers above 0; and it has an `alt` (non-empty after trimming) or `decorative` is `true`. Other slides are skipped. Order is the given order. Only the FIRST kept slide is written; the client takes the rest from the data block.
|
||||
3. A decorative slide writes `alt=""`.
|
||||
4. Variants: kept when `ratio`, `type` and `url` are non-empty, `width` is a whole number above 0 and `url` is a path of our host. Only `image/webp` variants are used here (a preload cannot say "AVIF if supported", so a second format would be fetched twice). `wide` variants make the `img` `srcset`, `tall` variants the `source` `srcset`; sorted by width ascending, written `URL WIDTHw`, joined by `, `.
|
||||
5. `focus` (`x` and `y` both between 0 and 1) is written as `style="object-position:X% Y%"` on the `img` (percentages without trailing zeros, at most two decimals); without a valid focus there is no `style`.
|
||||
6. Buttons: at most 2 (the first two valid ones). A button is valid with a non-empty `label` and a `target` that is an anchor (`#name`), a path (one leading `/`, not `//`, no backslash) or an `https://` address that parses. `lead` and `display` are not written in the HTML.
|
||||
7. Escape every text and attribute (`&` `&`, `<` `<`, `>` `>`, `"` `"`, `'` `'`). A new line in the title becomes `<br>` (after escaping).
|
||||
|
||||
## Output, HERO-HTML
|
||||
|
||||
`<picture class="cms-hero-picture">` + (when a `tall` webp variant exists: `<source media="(orientation: portrait)" srcset="TALL" sizes="100vw" type="image/webp">`) + `<img class="cms-hero-image" src="SRC"` + (when a `wide` webp variant exists: ` srcset="WIDE" sizes="100vw"`) + ` width="W" height="H" alt="ALT"` + (focus: ` style="object-position:X% Y%"`) + ` fetchpriority="high">` + `</picture>` + `<h1 class="cms-hero-title">` + (tagline: `<span class="cms-hero-tagline">TAGLINE</span> `) + `<span class="cms-hero-name">TITLE</span></h1>` + (when there are buttons: `<p class="cms-hero-buttons">` + `<a class="cms-hero-button" href="TARGET">LABEL</a>`... + `</p>`).
|
||||
|
||||
`src` is `image.src`; `W` and `H` are `image.width` and `image.height`. Selection is by orientation, not width, because the hero is as high as the screen.
|
||||
|
||||
## Output, HERO-PRELOAD
|
||||
|
||||
With a `tall` variant: `<link rel="preload" as="image" imagesrcset="TALL" imagesizes="100vw" media="(orientation: portrait)" fetchpriority="high">` followed by the landscape link with `media="(orientation: landscape)"`. The landscape link has `imagesrcset="WIDE" imagesizes="100vw"`, or `href="SRC"` when there is no wide set. Without a tall variant there is one link without `media`. The `srcset`, `sizes` and `media` values are byte for byte the same as in the picture; the golden files check this.
|
||||
|
||||
## Files
|
||||
|
||||
`hero-standard` (two slides, wide and tall, AVIF ignored), `hero-minimal` (no variants, no tagline, no button), `hero-two-lines` (line break, anchor, https and a third button that is cut, decorative slide), `hero-hostile` (escaping, unsafe buttons, unusable slides skipped), `hero-no-alt` and `hero-none` (empty). `seed.json` holds the seed for the ASF test CMS with a first focus estimate per photo.
|
||||
|
||||
URL scheme suggestion for the variants (the CMS decides): `/media/hero/<hash>/wide-1600.webp`, `/media/hero/<hash>/tall-960.avif`.
|
||||
@@ -0,0 +1 @@
|
||||
<link rel="preload" as="image" imagesrcset="/media/hero/a"b/w800.webp 800w" imagesizes="100vw" fetchpriority="high">
|
||||
@@ -0,0 +1 @@
|
||||
<picture class="cms-hero-picture"><img class="cms-hero-image" src="/media/hero/a"b/w1600.webp" srcset="/media/hero/a"b/w800.webp 800w" sizes="100vw" width="1600" height="1067" alt="Een "foto" <script>" fetchpriority="high"></picture><h1 class="cms-hero-title"><span class="cms-hero-tagline"><i>x</i></span> <span class="cms-hero-name"><b>"Andrea" & 'Slop'</b></span></h1><p class="cms-hero-buttons"><a class="cms-hero-button" href="/a?b=1&c="2""><Goed></a></p>
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"display": "slideshow",
|
||||
"title": "<b>\"Andrea\" & 'Slop'</b>",
|
||||
"tagline": "<i>x</i>",
|
||||
"buttons": [
|
||||
{ "label": "javascript", "target": "javascript:alert(1)" },
|
||||
{ "label": "Protocolvrij", "target": "//evil.example/x" },
|
||||
{ "label": "<Goed>", "target": "/a?b=1&c=\"2\"" }
|
||||
],
|
||||
"slides": [
|
||||
{
|
||||
"id": "skip1",
|
||||
"alt": "",
|
||||
"decorative": false,
|
||||
"image": { "width": 10, "height": 10, "src": "/media/x.webp" }
|
||||
},
|
||||
{
|
||||
"id": "skip2",
|
||||
"alt": "extern",
|
||||
"decorative": false,
|
||||
"image": {
|
||||
"width": 10,
|
||||
"height": 10,
|
||||
"src": "https://evil.example/x.webp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "skip3",
|
||||
"alt": "geen afmeting",
|
||||
"decorative": false,
|
||||
"image": { "width": 0, "height": 10, "src": "/media/x.webp" }
|
||||
},
|
||||
{
|
||||
"id": "a1",
|
||||
"alt": "Een \"foto\" <script>",
|
||||
"decorative": false,
|
||||
"image": {
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"src": "/media/hero/a\"b/w1600.webp",
|
||||
"variants": [
|
||||
{
|
||||
"ratio": "wide",
|
||||
"width": 800,
|
||||
"type": "image/webp",
|
||||
"url": "/media/hero/a\"b/w800.webp"
|
||||
},
|
||||
{
|
||||
"ratio": "wide",
|
||||
"width": 400,
|
||||
"type": "image/webp",
|
||||
"url": "https://evil.example/w400.webp"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<link rel="preload" as="image" href="/media/hero/abc123/w2560.webp" fetchpriority="high">
|
||||
@@ -0,0 +1 @@
|
||||
<picture class="cms-hero-picture"><img class="cms-hero-image" src="/media/hero/abc123/w2560.webp" width="2560" height="1702" alt="Lifestyle fotografie" fetchpriority="high"></picture><h1 class="cms-hero-title"><span class="cms-hero-name">Andrea Slop</span></h1>
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"display": "single",
|
||||
"title": "Andrea Slop",
|
||||
"buttons": [],
|
||||
"slides": [
|
||||
{
|
||||
"id": "a1",
|
||||
"alt": "Lifestyle fotografie",
|
||||
"decorative": false,
|
||||
"image": {
|
||||
"width": 2560,
|
||||
"height": 1702,
|
||||
"src": "/media/hero/abc123/w2560.webp"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"display": "slideshow",
|
||||
"title": "Titel",
|
||||
"buttons": [],
|
||||
"slides": [
|
||||
{
|
||||
"id": "x",
|
||||
"alt": "",
|
||||
"decorative": false,
|
||||
"image": { "width": 1, "height": 1, "src": "/m.webp" }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
null
|
||||
@@ -0,0 +1 @@
|
||||
<link rel="preload" as="image" imagesrcset="/media/hero/3f9a1c/tall-640.webp 640w, /media/hero/3f9a1c/tall-960.webp 960w" imagesizes="100vw" media="(orientation: portrait)" fetchpriority="high"><link rel="preload" as="image" imagesrcset="/media/hero/3f9a1c/wide-960.webp 960w, /media/hero/3f9a1c/wide-1600.webp 1600w" imagesizes="100vw" media="(orientation: landscape)" fetchpriority="high">
|
||||
@@ -0,0 +1 @@
|
||||
<picture class="cms-hero-picture"><source media="(orientation: portrait)" srcset="/media/hero/3f9a1c/tall-640.webp 640w, /media/hero/3f9a1c/tall-960.webp 960w" sizes="100vw" type="image/webp"><img class="cms-hero-image" src="/media/hero/3f9a1c/wide-1600.webp" srcset="/media/hero/3f9a1c/wide-960.webp 960w, /media/hero/3f9a1c/wide-1600.webp 1600w" sizes="100vw" width="1600" height="1067" alt="Zwangerschapsfoto in de duinen" style="object-position:50% 55%" fetchpriority="high"></picture><h1 class="cms-hero-title"><span class="cms-hero-tagline">Lifestyle fotograaf · Huizen</span> <span class="cms-hero-name">Andrea Slop</span></h1><p class="cms-hero-buttons"><a class="cms-hero-button" href="/over-mij">Lees meer</a></p>
|
||||
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"display": "slideshow",
|
||||
"title": "Andrea Slop",
|
||||
"tagline": "Lifestyle fotograaf · Huizen",
|
||||
"lead": null,
|
||||
"buttons": [{ "label": "Lees meer", "target": "/over-mij" }],
|
||||
"slides": [
|
||||
{
|
||||
"id": "11111111-1111-1111-1111-111111111111",
|
||||
"alt": "Zwangerschapsfoto in de duinen",
|
||||
"decorative": false,
|
||||
"image": {
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"focus": { "x": 0.5, "y": 0.55 },
|
||||
"src": "/media/hero/3f9a1c/wide-1600.webp",
|
||||
"variants": [
|
||||
{
|
||||
"ratio": "wide",
|
||||
"width": 1600,
|
||||
"type": "image/webp",
|
||||
"url": "/media/hero/3f9a1c/wide-1600.webp"
|
||||
},
|
||||
{
|
||||
"ratio": "wide",
|
||||
"width": 960,
|
||||
"type": "image/webp",
|
||||
"url": "/media/hero/3f9a1c/wide-960.webp"
|
||||
},
|
||||
{
|
||||
"ratio": "wide",
|
||||
"width": 1600,
|
||||
"type": "image/avif",
|
||||
"url": "/media/hero/3f9a1c/wide-1600.avif"
|
||||
},
|
||||
{
|
||||
"ratio": "wide",
|
||||
"width": 960,
|
||||
"type": "image/avif",
|
||||
"url": "/media/hero/3f9a1c/wide-960.avif"
|
||||
},
|
||||
{
|
||||
"ratio": "tall",
|
||||
"width": 960,
|
||||
"type": "image/webp",
|
||||
"url": "/media/hero/3f9a1c/tall-960.webp"
|
||||
},
|
||||
{
|
||||
"ratio": "tall",
|
||||
"width": 640,
|
||||
"type": "image/webp",
|
||||
"url": "/media/hero/3f9a1c/tall-640.webp"
|
||||
},
|
||||
{
|
||||
"ratio": "tall",
|
||||
"width": 960,
|
||||
"type": "image/avif",
|
||||
"url": "/media/hero/3f9a1c/tall-960.avif"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "22222222-2222-2222-2222-222222222222",
|
||||
"alt": "Knusse newbornfoto met de familie",
|
||||
"decorative": false,
|
||||
"image": {
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"focus": { "x": 0.45, "y": 0.5 },
|
||||
"src": "/media/hero/7b2e90/wide-1600.webp",
|
||||
"variants": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<link rel="preload" as="image" href="/media/hero/abc123/w1600.webp" fetchpriority="high">
|
||||
@@ -0,0 +1 @@
|
||||
<picture class="cms-hero-picture"><img class="cms-hero-image" src="/media/hero/abc123/w1600.webp" width="1600" height="1067" alt="" fetchpriority="high"></picture><h1 class="cms-hero-title"><span class="cms-hero-tagline">Fotografie</span> <span class="cms-hero-name">Andrea<br>Slop</span></h1><p class="cms-hero-buttons"><a class="cms-hero-button" href="#contact">Boek een shoot</a><a class="cms-hero-button" href="https://andreaslop.nl/portfolio">Portfolio</a></p>
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"display": "slideshow",
|
||||
"title": "Andrea\nSlop",
|
||||
"tagline": "Fotografie",
|
||||
"buttons": [
|
||||
{ "label": "Boek een shoot", "target": "#contact" },
|
||||
{ "label": "Portfolio", "target": "https://andreaslop.nl/portfolio" },
|
||||
{ "label": "Derde knop", "target": "/derde" }
|
||||
],
|
||||
"slides": [
|
||||
{
|
||||
"id": "a1",
|
||||
"alt": "",
|
||||
"decorative": true,
|
||||
"image": {
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"src": "/media/hero/abc123/w1600.webp",
|
||||
"variants": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"note": "Seed for the ASF hero on the test CMS. Focus points are a first estimate from looking at the photos (x and y between 0 and 1, from the top left); Bryan adjusts them in the admin. Sources are the existing exports in web/src/assets (not camera originals; never upscale).",
|
||||
"display": "slideshow",
|
||||
"title": "Andrea Slop",
|
||||
"tagline": "Lifestyle fotograaf · Huizen",
|
||||
"buttons": [{ "label": "Lees meer", "target": "/over-mij" }],
|
||||
"slides": [
|
||||
{
|
||||
"file": "hero-8.jpg",
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"alt": "Zwangerschapsfoto in de duinen",
|
||||
"focus": { "x": 0.5, "y": 0.55 },
|
||||
"subject": "belly and hands"
|
||||
},
|
||||
{
|
||||
"file": "hero-7.jpg",
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"alt": "Knusse newbornfoto met de familie",
|
||||
"focus": { "x": 0.45, "y": 0.5 },
|
||||
"subject": "the kiss on the baby"
|
||||
},
|
||||
{
|
||||
"file": "hero-1.jpg",
|
||||
"width": 2560,
|
||||
"height": 1702,
|
||||
"alt": "Lifestyle fotografie",
|
||||
"focus": { "x": 0.55, "y": 0.6 },
|
||||
"subject": "tattoo and heather"
|
||||
},
|
||||
{
|
||||
"file": "hero-2.jpg",
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"alt": "Zwangerschapsshoot in de buitenlucht",
|
||||
"focus": { "x": 0.45, "y": 0.45 },
|
||||
"subject": "the couple"
|
||||
},
|
||||
{
|
||||
"file": "hero-3.jpg",
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"alt": "Newbornshoot van een pasgeboren baby",
|
||||
"focus": { "x": 0.45, "y": 0.4 },
|
||||
"subject": "the baby's face"
|
||||
},
|
||||
{
|
||||
"file": "hero-4.jpg",
|
||||
"width": 2048,
|
||||
"height": 1362,
|
||||
"alt": "Spontaan portret buiten",
|
||||
"focus": { "x": 0.45, "y": 0.35 },
|
||||
"subject": "the face"
|
||||
},
|
||||
{
|
||||
"file": "hero-5.jpg",
|
||||
"width": 1600,
|
||||
"height": 1067,
|
||||
"alt": "Natuurlijke lifestylefoto",
|
||||
"focus": { "x": 0.5, "y": 0.55 },
|
||||
"subject": "the hands with the ring"
|
||||
},
|
||||
{
|
||||
"file": "hero-6.jpg",
|
||||
"width": 2048,
|
||||
"height": 1362,
|
||||
"alt": "Portret in de natuur",
|
||||
"focus": { "x": 0.5, "y": 0.35 },
|
||||
"subject": "the face"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user