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:
+1
-1
@@ -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):
|
||||
|
||||
`<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).
|
||||
`<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). An optional per-site setting `Hero:TitlePrefix` (default empty; SLP Software: `"SLP Software: "`) writes `<span class="cms-hero-title-prefix">SLP Software: </span>` (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).
|
||||
|
||||
@@ -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 (`<span class="cms-hero-title-prefix">`), 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). |
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -68,6 +68,14 @@ public class SiteContractTests
|
||||
SiteFiles.Committed(site).GetValue<bool>("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)
|
||||
|
||||
@@ -64,7 +64,48 @@ public class HeroTextOnlyTests
|
||||
HeroPictureRenderer.Render(hero, textOnlyRegion: true).IsEmpty.Should().BeTrue();
|
||||
}
|
||||
|
||||
private const string Page = "<head><!--CMS:HERO-PRELOAD--><!--/CMS:HERO-PRELOAD--></head><body><!--CMS:HERO-HTML-->baked<!--/CMS:HERO-HTML--></body>";
|
||||
[Fact]
|
||||
public void ThePrefix_IsTheFirstHiddenPartOfTheH1_AndIsEncoded()
|
||||
{
|
||||
var injection = HeroPictureRenderer.Render(TextOnly("Titel", "Label", null), textOnlyRegion: true, titlePrefix: "SLP & Co: ");
|
||||
|
||||
injection.Region.Should().Be("<h1 class=\"cms-hero-title\"><span class=\"cms-hero-title-prefix\">SLP & Co: </span><span class=\"cms-hero-tagline\">Label</span> <span class=\"cms-hero-title-lines\">Titel</span></h1>");
|
||||
}
|
||||
|
||||
[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<IHeroPageModel>();
|
||||
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("<h1 class=\"cms-hero-title\"><span class=\"cms-hero-title-prefix\">SLP Software: </span><span class=\"cms-hero-title-lines\">");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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><br></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> ");
|
||||
|
||||
Reference in New Issue
Block a user