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
@@ -26,5 +26,5 @@ Kept while Bryan was away (2026-11-16): no questions to him, a likely assumption
| 20 | **ASF production** hosting (IIS, MijnHostingPartner): can the application pool write a data directory, and is it backed up? | Unknown; Bryan tests with ASF. The storage sits behind `IMediaStore` so a database store can follow. | Build the database store (2 to 3 days). | `IMediaStore`, `FileSystemMediaStore` |
| 21 | **SLS title** on the page. | The CMS delivers one title with line breaks; the SLP site derives the screen-reader title from the lines and adds the brand prefix itself. | Another split (a separate `heading` field) would be a model change. | `HeroSaveRequest.Title`, `HeroPictureRenderer` (`<br>`), SLS site |
| 22 | **Production seed**. | Not done; only the test hosts, with Bryan's password, after his go. | n/a | `scripts/Seed-Hero.ps1`, `docs/release-checklist-productie.md` section 4b |
| 23 | What does the host write for a hero **without any slide** (SLP Software)? | A text-only region in the first HTML (so a CMS change is visible without JavaScript, LCP is the text): `h1.cms-hero-title` with an optional `span.cms-hero-tagline` and `span.cms-hero-title-lines` (title lines separated by `<br>`, no brand prefix), then `p.cms-hero-lead` (lead, line breaks as `<br>`) and `p.cms-hero-buttons` with `a.cms-hero-button`. Nothing to preload, and the preload region is left as built. A hero WITH slides but none usable stays empty (ASF unchanged). If the ASF CMS hero ever has no slides at all, ASF would get this text region instead of its baked hero. | A flag per site, or text-only only when the markers say so (for instance `CMS:HERO-TEXT`). | `HeroPictureRenderer.Render` and `TextOnlyRegion`, `HeroHtmlTransform.ApplyAsync`, `HeroTextOnlyTests` |
| 23 | What does the host write for a hero **without any slide** (SLP Software)? | A text-only region in the first HTML (so a CMS change is visible without JavaScript, LCP is the text): `h1.cms-hero-title` with an optional `span.cms-hero-tagline` and `span.cms-hero-title-lines` (title lines separated by `<br>`, no brand prefix), then `p.cms-hero-lead` (lead, line breaks as `<br>`) and `p.cms-hero-buttons` with `a.cms-hero-button`. Nothing to preload, and the preload region is left as built. A hero WITH slides but none usable stays empty (ASF unchanged). This is a per-site switch, `Hero:TextOnlyRegion`: on in the committed settings of the SLP site, off by default (so ASF keeps its baked hero when its CMS hero has no slide, as ASF asked). | A separate marker for the text region instead of a switch. | `HeroOptions.TextOnlyRegion`, `HeroPictureRenderer.Render` and `TextOnlyRegion`, `HeroHtmlTransform.ApplyAsync`, `Api.SlpSoftware/appsettings.json`, `HeroTextOnlyTests` |
| 24 | Does the data block carry the hero when it has no slides? | Yes (intended): the site reads the hero from the data block, the baked block is `{}`. | n/a | `HeroPageModel`, `HeroDataContributor` |
@@ -75,6 +75,6 @@ Not yet built on the ASF side (after this design): hydration and slider from the
## Text-only hero (SLP Software), added 2026-11-16
A hero **without any slide** is written as text (SLP Software has no images; the site reads the same hero from the data block):
A hero **without any slide** is written as text, **only on a site that asks for it** with the setting `Hero:TextOnlyRegion=true` (SLP Software: no images; it reads the same hero from the data block). The setting is off by default and off for ASF, so for ASF a hero without a slide changes nothing in the page (the baked hero stays, also in the preload region):
`<h1 class="cms-hero-title">` + (tagline: `<span class="cms-hero-tagline">TAGLINE</span> `) + `<span class="cms-hero-title-lines">LINE<br>LINE</span></h1>` + (lead: `<p class="cms-hero-lead">LEAD</p>`, line breaks as `<br>`) + (buttons: `<p class="cms-hero-buttons"><a class="cms-hero-button" href="TARGET">LABEL</a>...</p>`, at most two). The title lines carry no brand prefix: the site adds "SLP Software:" to its own screen-reader title. There is nothing to preload, so `CMS:HERO-PRELOAD` is left as the build made it. Everything is HTML-encoded. A hero with slides of which none is usable is still empty (the ASF golden files are unchanged).
+1
View File
@@ -27,6 +27,7 @@ De admin toont alleen een badge Live of Niet live.
|---|---|
| `Media__Directory` | De map voor de afbeeldingen, **buiten de release** en buiten de webroot. Zonder deze instelling (of als de map niet beschrijfbaar is) staan uploads uit; bestaande bestanden en de publieke hero blijven werken. Niet in een committed appsettings-bestand. |
| `Media__MaxUploadBytes` (10 MB), `Media__MaxPixels` (64 miljoen), `Media__MaxParallelJobs` (2), `Media__DecodeTimeoutSeconds` (20), `Media__MaxTotalBytes` (2 GB), `Media__RetentionDays` (7) | Grenzen en bewaartijd; standaardwaarden zijn bedoeld om te blijven. |
| `Hero__TextOnlyRegion` | `true` voor een site waarvan de hero geen afbeeldingen heeft (SLP Software; staat in de committed instellingen van die site): een hero zonder slides wordt dan als tekst (titelregels, lead, knoppen) in de eerste HTML geschreven. Uit (standaard, ook voor ASF): een hero zonder slides laat de pagina ongemoeid. |
| `Hero__MaxPublishedSlides` | Technische bovengrens op het aantal gepubliceerde slides (standaard 50). |
| `RateLimiting__HeroPublic`, `__MediaPublic`, `__HeroUpload` | Snelheidsbeleid (standaard 120 per 60 s, 600 per 60 s, 20 per uur per gebruiker). |
@@ -9,6 +9,8 @@
}
},
"AllowedHosts": "*",
// The SLP hero has no images: the host writes its title, lead and buttons as text into the first HTML.
"Hero": { "TextOnlyRegion": true },
"Website": {
// Secure default: every response carries noindex and /robots.txt disallows all. A production
// instance must set Website__NoIndex=false and Website__PublicBaseUrl=https://slpsoftware.nl explicitly;
@@ -59,6 +59,15 @@ public class SiteContractTests
(configured ?? "SpaFallback").Should().Be(mode);
}
[Theory]
[InlineData(SiteFiles.SlpSoftware, true)]
[InlineData(SiteFiles.AndreaSlopFotografie, false)]
public void TheHeroIsWrittenAsTextOnlyForTheSiteWithoutHeroImages(string site, bool textOnly)
{
// SLP Software's hero has no images, so the host writes it as text; ASF's baked hero is a picture and stays when the CMS hero has no slide.
SiteFiles.Committed(site).GetValue<bool>("Hero:TextOnlyRegion").Should().Be(textOnly);
}
[Theory]
[MemberData(nameof(Sites))]
public void WebsiteIsNoIndex_ByDefault(string site)
@@ -6,7 +6,10 @@ using SlpModularCms.Modules.Hero.Services;
namespace SlpModularCms.Modules.Hero.Tests;
/// <summary>A hero without slides (SLP Software): the host writes the title, the lead and the buttons into the first HTML.</summary>
/// <summary>
/// A hero without slides (SLP Software): when the site asks for it (<c>Hero:TextOnlyRegion</c>) the host writes the
/// title, the lead and the buttons into the first HTML; otherwise (ASF) the baked page stays.
/// </summary>
public class HeroTextOnlyTests
{
private static PublicHeroDto TextOnly(string title = "Websites,\napps\n& meer.", string? tagline = null, string? lead = "Een lead.", params HeroButtonDto[] buttons)
@@ -17,7 +20,7 @@ public class HeroTextOnlyTests
{
var hero = TextOnly(buttons: [new HeroButtonDto("Bekijk pakketten", "#pakketten"), new HeroButtonDto("Plan een gesprek", "#contact")]);
var injection = HeroPictureRenderer.Render(hero);
var injection = HeroPictureRenderer.Render(hero, textOnlyRegion: true);
injection.Region.Should().Be(
"<h1 class=\"cms-hero-title\"><span class=\"cms-hero-title-lines\">Websites,<br>apps<br>&amp; meer.</span></h1>" +
@@ -27,10 +30,19 @@ public class HeroTextOnlyTests
injection.IsEmpty.Should().BeFalse();
}
[Fact]
public void WithoutTheSiteAskingForIt_AHeroWithoutSlides_LeavesTheBakedHero()
{
var hero = TextOnly(buttons: [new HeroButtonDto("Knop", "#x")]);
HeroPictureRenderer.Render(hero).IsEmpty.Should().BeTrue();
HeroPictureRenderer.Render(hero, textOnlyRegion: false).IsEmpty.Should().BeTrue();
}
[Fact]
public void WithoutALead_OrButtons_ThosePartsAreLeftOut_AndATaglineComesFirst()
{
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null));
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null), textOnlyRegion: true);
injection.Region.Should().Be("<h1 class=\"cms-hero-title\"><span class=\"cms-hero-tagline\">Label</span> <span class=\"cms-hero-title-lines\">Titel</span></h1>");
}
@@ -38,30 +50,41 @@ public class HeroTextOnlyTests
[Fact]
public void TheLead_KeepsItsLineBreaks_AndEverythingIsEncoded()
{
var injection = HeroPictureRenderer.Render(TextOnly("<b>x</b>", null, "a & b\nc \"d\"", new HeroButtonDto("<i>", "/p?a=1&b=2")));
var injection = HeroPictureRenderer.Render(TextOnly("<b>x</b>", null, "a & b\nc \"d\"", new HeroButtonDto("<i>", "/p?a=1&b=2")), textOnlyRegion: true);
injection.Region.Should().Contain("&lt;b&gt;x&lt;/b&gt;").And.Contain("a &amp; b<br>c &quot;d&quot;").And.Contain("href=\"/p?a=1&amp;b=2\">&lt;i&gt;</a>");
injection.Region.Should().NotContain("<b>").And.NotContain("<i>");
}
[Fact]
public void AHeroWithSlidesThatAreAllUnusable_StaysEmpty_AsForTheAsfSite()
public void AHeroWithSlidesThatAreAllUnusable_StaysEmpty_EvenWhenTheSiteAsksForText()
{
var hero = new PublicHeroDto("single", "Titel", null, null, [], [new PublicSlideDto("x", "", false, new PublicImageDto(1, 1, new FocusDto(0.5, 0.5, 1), "/m.webp", []))]);
HeroPictureRenderer.Render(hero).IsEmpty.Should().BeTrue();
HeroPictureRenderer.Render(hero, textOnlyRegion: true).IsEmpty.Should().BeTrue();
}
[Fact]
public async Task TheTransform_FillsTheTextRegion_AndLeavesThePreloadRegionAlone()
private const string Page = "<head><!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD--></head><body><!--CMS:HERO-HTML-->baked<!--/CMS:HERO-HTML--></body>";
private static HeroHtmlTransform Transform(bool textOnly)
{
var model = Substitute.For<IHeroPageModel>();
model.GetAsync(default).ReturnsForAnyArgs(TextOnly());
const string page = "<head><!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD--></head><body><!--CMS:HERO-HTML-->baked<!--/CMS:HERO-HTML--></body>";
return new HeroHtmlTransform(model, Options.Create(new HeroOptions { TextOnlyRegion = textOnly }));
}
var html = await new HeroHtmlTransform(model).ApplyAsync(page, new HtmlTransformContext("https://x"), default);
[Fact]
public async Task TheTransform_FillsTheTextRegion_WhenTheSiteAsksForIt_AndLeavesThePreloadRegionAlone()
{
var html = await Transform(textOnly: true).ApplyAsync(Page, new HtmlTransformContext("https://x"), default);
html.Should().Contain("<!--CMS:HERO-HTML--><h1 class=\"cms-hero-title\">").And.NotContain("baked");
html.Should().Contain("<!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD-->");
}
[Fact]
public async Task TheTransform_LeavesTheWholePageAlone_WhenTheSiteDoesNotAskForText()
{
(await Transform(textOnly: false).ApplyAsync(Page, new HtmlTransformContext("https://x"), default)).Should().Be(Page);
}
}
@@ -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);