Hero: instelling Hero:TitlePrefix (verborgen merkvoorvoegsel in de h1 van de tekst-only-regio)

SLP-composite: 'SLP Software: '; ASF leeg (golden files ongewijzigd). Tests en contract bijgewerkt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 20:42:49 +01:00
co-authored by Claude Sonnet 5.5
parent 4c7787caf2
commit 969bb14d86
8 changed files with 70 additions and 7 deletions
@@ -57,7 +57,7 @@ public sealed class HeroHtmlTransform(IHeroPageModel model, Microsoft.Extensions
public async Task<string> ApplyAsync(string html, HtmlTransformContext context, CancellationToken cancellationToken)
{
var rendered = HeroPictureRenderer.Render(await model.GetAsync(cancellationToken), options?.Value.TextOnlyRegion ?? false);
var rendered = HeroPictureRenderer.Render(await model.GetAsync(cancellationToken), options?.Value.TextOnlyRegion ?? false, options?.Value.TitlePrefix ?? string.Empty);
if (rendered.IsEmpty)
{
return html;
@@ -20,6 +20,12 @@ public sealed class HeroOptions
/// that baked hero when the CMS hero has no slide (fail open).
/// </summary>
public bool TextOnlyRegion { get; set; }
/// <summary>
/// Brand text written as the first, visually hidden part of the h1 of the text-only region (SLP Software:
/// "SLP Software: "), so crawlers and screen readers read the full title. Empty (default) writes nothing.
/// </summary>
public string TitlePrefix { get; set; } = string.Empty;
}
/// <summary>Turns stored entities into the shapes of the API and the data block. Pure.</summary>
@@ -29,7 +29,7 @@ public static class HeroPictureRenderer
private const string Portrait = "(orientation: portrait)";
private const string Landscape = "(orientation: landscape)";
public static HeroInjection Render(PublicHeroDto? hero, bool textOnlyRegion = false)
public static HeroInjection Render(PublicHeroDto? hero, bool textOnlyRegion = false, string titlePrefix = "")
{
if (hero is null || string.IsNullOrWhiteSpace(hero.Title))
{
@@ -41,7 +41,7 @@ public static class HeroPictureRenderer
// preload. Otherwise, and for a hero WITH slides of which none is usable, the region stays empty (ASF).
if ((hero.Slides ?? []).Count == 0)
{
return textOnlyRegion ? new HeroInjection(TextOnlyRegion(hero), string.Empty) : HeroInjection.None;
return textOnlyRegion ? new HeroInjection(TextOnlyRegion(hero, titlePrefix), string.Empty) : HeroInjection.None;
}
var slide = (hero.Slides ?? []).FirstOrDefault(IsUsable);
@@ -99,10 +99,16 @@ public static class HeroPictureRenderer
/// <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)
private static string TextOnlyRegion(PublicHeroDto hero, string titlePrefix)
{
var html = new StringBuilder();
html.Append("<h1 class=\"cms-hero-title\">");
// The brand prefix (Hero:TitlePrefix) is text for crawlers and screen readers; the site styles it visually hidden.
if (!string.IsNullOrWhiteSpace(titlePrefix))
{
html.Append("<span class=\"cms-hero-title-prefix\">").Append(Encode(titlePrefix)).Append("</span>");
}
if (!string.IsNullOrWhiteSpace(hero.Tagline))
{
html.Append("<span class=\"cms-hero-tagline\">").Append(Encode(hero.Tagline)).Append("</span> ");