diff --git a/aidlc-docs/features/hero-module/inception/requirements/site-contract-agreed-with-asf.md b/aidlc-docs/features/hero-module/inception/requirements/site-contract-agreed-with-asf.md index e43aa45..1d4dd7d 100644 --- a/aidlc-docs/features/hero-module/inception/requirements/site-contract-agreed-with-asf.md +++ b/aidlc-docs/features/hero-module/inception/requirements/site-contract-agreed-with-asf.md @@ -77,4 +77,4 @@ Not yet built on the ASF side (after this design): hydration and slider from the 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): -`

` + (tagline: `TAGLINE `) + `LINE
LINE

` + (lead: `

LEAD

`, line breaks as `
`) + (buttons: `

LABEL...

`, 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). +`

` + (tagline: `TAGLINE `) + `LINE
LINE

` + (lead: `

LEAD

`, line breaks as `
`) + (buttons: `

LABEL...

`, at most two). An optional per-site setting `Hero:TitlePrefix` (default empty; SLP Software: `"SLP Software: "`) writes `SLP Software: ` (encoded) as the **first child of the h1**, before tagline and title lines, so crawlers and screen readers read "SLP Software: Websites, apps & meer."; the site styles that class visually hidden (sr-only). The visible title lines stay in `span.cms-hero-title-lines`. The prefix is only used in the text-only region (never for a hero with slides; ASF leaves it empty, so its golden files are unchanged). 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). diff --git a/docs/hero-module.md b/docs/hero-module.md index 552cd33..19351bc 100644 --- a/docs/hero-module.md +++ b/docs/hero-module.md @@ -28,6 +28,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__TitlePrefix` | Merktekst die in de tekst-only-regio als eerste, visueel te verbergen deel van de h1 wordt geschreven (``), zodat crawlers en schermlezers de volledige titel lezen. SLP Software: `"SLP Software: "` (committed instelling); leeg (standaard, ook ASF) schrijft niets. De site verbergt de klasse zelf visueel. | | `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). | diff --git a/src/SlpModularCms.Api.SlpSoftware/appsettings.json b/src/SlpModularCms.Api.SlpSoftware/appsettings.json index 91631c8..eb5ce6e 100644 --- a/src/SlpModularCms.Api.SlpSoftware/appsettings.json +++ b/src/SlpModularCms.Api.SlpSoftware/appsettings.json @@ -10,7 +10,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 }, + // TitlePrefix: visually hidden brand text before the title lines in the h1 (for crawlers and screen readers). + "Hero": { "TextOnlyRegion": true, "TitlePrefix": "SLP Software: " }, "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; diff --git a/src/SlpModularCms.Api.Tests/SiteContractTests.cs b/src/SlpModularCms.Api.Tests/SiteContractTests.cs index 00457b8..90baa19 100644 --- a/src/SlpModularCms.Api.Tests/SiteContractTests.cs +++ b/src/SlpModularCms.Api.Tests/SiteContractTests.cs @@ -68,6 +68,14 @@ public class SiteContractTests SiteFiles.Committed(site).GetValue("Hero:TextOnlyRegion").Should().Be(textOnly); } + [Theory] + [InlineData(SiteFiles.SlpSoftware, "SLP Software: ")] + [InlineData(SiteFiles.AndreaSlopFotografie, "")] + public void TheHeroTitlePrefix_IsSetForSlpSoftware_AndEmptyForAsf(string site, string prefix) + { + (SiteFiles.Committed(site)["Hero:TitlePrefix"] ?? string.Empty).Should().Be(prefix); + } + [Theory] [MemberData(nameof(Sites))] public void WebsiteIsNoIndex_ByDefault(string site) diff --git a/src/SlpModularCms.Modules.Hero.Tests/HeroTextOnlyTests.cs b/src/SlpModularCms.Modules.Hero.Tests/HeroTextOnlyTests.cs index 3ce3da0..397d931 100644 --- a/src/SlpModularCms.Modules.Hero.Tests/HeroTextOnlyTests.cs +++ b/src/SlpModularCms.Modules.Hero.Tests/HeroTextOnlyTests.cs @@ -64,7 +64,48 @@ public class HeroTextOnlyTests HeroPictureRenderer.Render(hero, textOnlyRegion: true).IsEmpty.Should().BeTrue(); } - private const string Page = "baked"; + [Fact] + public void ThePrefix_IsTheFirstHiddenPartOfTheH1_AndIsEncoded() + { + var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null), textOnlyRegion: true, titlePrefix: "SLP & Co: "); + + injection.Region.Should().Be("

SLP & Co: Label Titel

"); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + public void AnEmptyPrefix_ChangesNothing(string prefix) + { + var hero = TextOnly(); + + HeroPictureRenderer.Render(hero, textOnlyRegion: true, titlePrefix: prefix).Region + .Should().Be(HeroPictureRenderer.Render(hero, textOnlyRegion: true).Region).And.NotContain("title-prefix"); + } + + [Fact] + public void APictureHero_NeverGetsThePrefix() + { + var variant = new HeroVariantDto("wide", 640, 427, "image/webp", "/media/hero/0123456789abcdef/wide-640.webp"); + var image = new PublicImageDto(1600, 1067, new FocusDto(0.5, 0.5, 1), "/media/hero/0123456789abcdef/wide-640.webp", [variant]); + var hero = new PublicHeroDto("single", "Titel", null, null, [], [new PublicSlideDto("alt", "", false, image)]); + + HeroPictureRenderer.Render(hero, textOnlyRegion: true, titlePrefix: "SLP: ").Region.Should().NotContain("title-prefix"); + } + + [Fact] + public async Task TheTransform_PassesTheConfiguredPrefix() + { + var model = Substitute.For(); + model.GetAsync(default).ReturnsForAnyArgs(TextOnly()); + var transform = new HeroHtmlTransform(model, Options.Create(new HeroOptions { TextOnlyRegion = true, TitlePrefix = "SLP Software: " })); + + var html = await transform.ApplyAsync(Page, new HtmlTransformContext("https://x"), default); + + html.Should().Contain("

SLP Software: "); + } + + private const string Page ="baked"; private static HeroHtmlTransform Transform(bool textOnly) { diff --git a/src/SlpModularCms.Modules.Hero/Services/HeroInjection.cs b/src/SlpModularCms.Modules.Hero/Services/HeroInjection.cs index 7b02b48..2440a7b 100644 --- a/src/SlpModularCms.Modules.Hero/Services/HeroInjection.cs +++ b/src/SlpModularCms.Modules.Hero/Services/HeroInjection.cs @@ -57,7 +57,7 @@ public sealed class HeroHtmlTransform(IHeroPageModel model, Microsoft.Extensions public async Task 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; diff --git a/src/SlpModularCms.Modules.Hero/Services/HeroMapping.cs b/src/SlpModularCms.Modules.Hero/Services/HeroMapping.cs index 94023e6..9ab0c9a 100644 --- a/src/SlpModularCms.Modules.Hero/Services/HeroMapping.cs +++ b/src/SlpModularCms.Modules.Hero/Services/HeroMapping.cs @@ -20,6 +20,12 @@ public sealed class HeroOptions /// that baked hero when the CMS hero has no slide (fail open). /// public bool TextOnlyRegion { get; set; } + + /// + /// 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. + /// + public string TitlePrefix { get; set; } = string.Empty; } /// Turns stored entities into the shapes of the API and the data block. Pure. diff --git a/src/SlpModularCms.Modules.Hero/Services/HeroPictureRenderer.cs b/src/SlpModularCms.Modules.Hero/Services/HeroPictureRenderer.cs index 0e12d81..0ddecc6 100644 --- a/src/SlpModularCms.Modules.Hero/Services/HeroPictureRenderer.cs +++ b/src/SlpModularCms.Modules.Hero/Services/HeroPictureRenderer.cs @@ -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 /// span.cms-hero-title-lines separated by <br> (no brand prefix: the site adds it to its own /// screen-reader title), then p.cms-hero-lead and the buttons row. /// - private static string TextOnlyRegion(PublicHeroDto hero) + private static string TextOnlyRegion(PublicHeroDto hero, string titlePrefix) { var html = new StringBuilder(); html.Append("

"); + // The brand prefix (Hero:TitlePrefix) is text for crawlers and screen readers; the site styles it visually hidden. + if (!string.IsNullOrWhiteSpace(titlePrefix)) + { + html.Append("").Append(Encode(titlePrefix)).Append(""); + } + if (!string.IsNullOrWhiteSpace(hero.Tagline)) { html.Append("").Append(Encode(hero.Tagline)).Append(" ");