Hero: tekst-only regio alleen bij Hero:TextOnlyRegion (aan voor SLP, uit voor ASF: de ingebakken hero blijft)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:57:10 +01:00
co-authored by Claude Sonnet 5.5
parent d3525c1316
commit 0b003f5795
9 changed files with 61 additions and 18 deletions
@@ -46,7 +46,7 @@ public sealed class HeroPageModel(IPublicHeroService publicHero, IMediaStore sto
}
/// <summary>Fills the hero regions of a page: <c>&lt;!--CMS:HERO-HTML--&gt;</c> in the body and <c>&lt;!--CMS:HERO-PRELOAD--&gt;</c> in the head. Fail-open: no hero means the baked page stays.</summary>
public sealed class HeroHtmlTransform(IHeroPageModel model) : IHtmlPageTransform
public sealed class HeroHtmlTransform(IHeroPageModel model, Microsoft.Extensions.Options.IOptions<HeroOptions>? options = null) : IHtmlPageTransform
{
public const string HtmlRegion = "CMS:HERO-HTML";
public const string PreloadRegion = "CMS:HERO-PRELOAD";
@@ -57,7 +57,7 @@ public sealed class HeroHtmlTransform(IHeroPageModel model) : IHtmlPageTransform
public async Task<string> ApplyAsync(string html, HtmlTransformContext context, CancellationToken cancellationToken)
{
var rendered = HeroPictureRenderer.Render(await model.GetAsync(cancellationToken));
var rendered = HeroPictureRenderer.Render(await model.GetAsync(cancellationToken), options?.Value.TextOnlyRegion ?? false);
if (rendered.IsEmpty)
{
return html;
@@ -13,6 +13,13 @@ public sealed class HeroOptions
/// carry more slides than this, so the first HTML cannot grow without bound. Everything above stays saved.
/// </summary>
public int MaxPublishedSlides { get; set; } = 50;
/// <summary>
/// Whether a hero without any slide is written into the page as text (title lines, lead, buttons). On for a site
/// that has no images in its hero (SLP Software); off by default, so a site whose baked hero is a picture (ASF) keeps
/// that baked hero when the CMS hero has no slide (fail open).
/// </summary>
public bool TextOnlyRegion { get; set; }
}
/// <summary>Turns stored entities into the shapes of the API and the data block. Pure.</summary>
@@ -29,18 +29,19 @@ public static class HeroPictureRenderer
private const string Portrait = "(orientation: portrait)";
private const string Landscape = "(orientation: landscape)";
public static HeroInjection Render(PublicHeroDto? hero)
public static HeroInjection Render(PublicHeroDto? hero, bool textOnlyRegion = false)
{
if (hero is null || string.IsNullOrWhiteSpace(hero.Title))
{
return HeroInjection.None;
}
// 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).
// A hero without any slide is a text-only hero (SLP Software, when the site asks for it with
// Hero:TextOnlyRegion): the region holds the title lines, the lead and the buttons, and there is nothing to
// preload. Otherwise, and for a hero WITH slides of which none is usable, the region stays empty (ASF).
if ((hero.Slides ?? []).Count == 0)
{
return new HeroInjection(TextOnlyRegion(hero), string.Empty);
return textOnlyRegion ? new HeroInjection(TextOnlyRegion(hero), string.Empty) : HeroInjection.None;
}
var slide = hero.Slides.FirstOrDefault(IsUsable);