Hero: tekst-only regio voor een hero zonder slides (SLP), e2e-test op de echte ASF-build, bijgewerkte aannames en contract

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:54:37 +01:00
co-authored by Claude Sonnet 5.5
parent b749902f4a
commit d3525c1316
7 changed files with 271 additions and 16 deletions
@@ -64,7 +64,9 @@ public sealed class HeroHtmlTransform(IHeroPageModel model) : IHtmlPageTransform
}
html = HtmlMarkerEditor.ReplaceRegion(html, HtmlRegion, rendered.Region);
return HtmlMarkerEditor.ReplaceRegion(html, PreloadRegion, rendered.Preload);
// A text-only hero has nothing to preload: the page keeps whatever its build put there.
return rendered.Preload.Length == 0 ? html : HtmlMarkerEditor.ReplaceRegion(html, PreloadRegion, rendered.Preload);
}
}
@@ -36,7 +36,14 @@ public static class HeroPictureRenderer
return HeroInjection.None;
}
var slide = (hero.Slides ?? []).FirstOrDefault(IsUsable);
// A hero without any slide is a text-only hero (SLP Software): the region holds the title lines, the lead and
// the buttons, and there is nothing to preload. A hero WITH slides of which none is usable stays empty (ASF).
if ((hero.Slides ?? []).Count == 0)
{
return new HeroInjection(TextOnlyRegion(hero), string.Empty);
}
var slide = hero.Slides.FirstOrDefault(IsUsable);
if (slide is null)
{
return HeroInjection.None;
@@ -81,23 +88,54 @@ public static class HeroPictureRenderer
html.Append("<span class=\"cms-hero-tagline\">").Append(Encode(hero.Tagline)).Append("</span> ");
}
html.Append("<span class=\"cms-hero-name\">").Append(string.Join("<br>", hero.Title.Replace("\r\n", "\n").Split('\n').Select(Encode))).Append("</span></h1>");
html.Append("<span class=\"cms-hero-name\">").Append(Lines(hero.Title)).Append("</span></h1>");
AppendButtons(html, hero);
return html.ToString();
}
var buttons = (hero.Buttons ?? []).Where(IsUsable).Take(2).ToList();
if (buttons.Count > 0)
/// <summary>
/// The text-only hero: <c>h1.cms-hero-title</c> with the tagline (when there is one) and the title lines in
/// <c>span.cms-hero-title-lines</c> separated by <c>&lt;br&gt;</c> (no brand prefix: the site adds it to its own
/// screen-reader title), then <c>p.cms-hero-lead</c> and the buttons row.
/// </summary>
private static string TextOnlyRegion(PublicHeroDto hero)
{
var html = new StringBuilder();
html.Append("<h1 class=\"cms-hero-title\">");
if (!string.IsNullOrWhiteSpace(hero.Tagline))
{
html.Append("<p class=\"cms-hero-buttons\">");
foreach (var button in buttons)
{
html.Append("<a class=\"cms-hero-button\" href=\"").Append(Encode(button.Target)).Append("\">").Append(Encode(button.Label)).Append("</a>");
}
html.Append("</p>");
html.Append("<span class=\"cms-hero-tagline\">").Append(Encode(hero.Tagline)).Append("</span> ");
}
html.Append("<span class=\"cms-hero-title-lines\">").Append(Lines(hero.Title)).Append("</span></h1>");
if (!string.IsNullOrWhiteSpace(hero.Lead))
{
html.Append("<p class=\"cms-hero-lead\">").Append(Lines(hero.Lead.Trim())).Append("</p>");
}
AppendButtons(html, hero);
return html.ToString();
}
private static string Lines(string text) => string.Join("<br>", text.Replace("\r\n", "\n").Split('\n').Select(Encode));
private static void AppendButtons(StringBuilder html, PublicHeroDto hero)
{
var buttons = (hero.Buttons ?? []).Where(IsUsable).Take(2).ToList();
if (buttons.Count == 0)
{
return;
}
html.Append("<p class=\"cms-hero-buttons\">");
foreach (var button in buttons)
{
html.Append("<a class=\"cms-hero-button\" href=\"").Append(Encode(button.Target)).Append("\">").Append(Encode(button.Label)).Append("</a>");
}
html.Append("</p>");
}
private static string Preload(string src, string wide, string tall)
{
const string head = "<link rel=\"preload\" as=\"image\"";