H6: seed-script voor de hero (ASF en SLP), docs/hero-module.md, rooktest voor Hero en de media-endpoint, productie-checklist

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 16:09:14 +01:00
co-authored by Claude Sonnet 5.5
parent 5559d459c3
commit 7ae05e3fc0
7 changed files with 328 additions and 3 deletions
+141
View File
@@ -0,0 +1,141 @@
<#
.SYNOPSIS
Puts the hero of a site into a CMS through the admin API: uploads the photos, sets their focus points and saves the
hero. Test hosts only unless you deliberately point it somewhere else. Skips a CMS that already has a hero.
.DESCRIPTION
Logs in with an admin account (the password is asked interactively, as a secure string; it is never written to disk,
to the console or to a log). Then, from -SeedFile: uploads every slide photo from -ImagesDirectory (the same photo
again is the same image, so a second run does not duplicate anything), sets the focus point of each photo, and saves
the hero (texts, buttons, display and the slides with their alt texts) in one go.
.PARAMETER BaseUrl
Root of the host, e.g. https://test.andreaslop.nl (no trailing /api).
.PARAMETER SeedFile
JSON: title (new lines as \n), tagline, lead, display (single or slideshow), buttons [{label, target}],
slides [{file, alt, decorative, focus {x, y}}]. Default: hero-asf.json next to this script. hero-sls.json is the
text-only hero of SLP Software (no slides).
.PARAMETER ImagesDirectory
The folder that holds the files named in the slides (required when the seed has slides). For ASF these are the
existing exports hero-1.jpg to hero-8.jpg of the website repository (web/src/assets).
.PARAMETER Email
Admin e-mail address. Asked when omitted.
.PARAMETER Force
Replace an existing hero as well (the photos stay; the slide list is replaced).
.PARAMETER WhatIf
Shows what would be done without logging in or writing anything.
.EXAMPLE
./scripts/Seed-Hero.ps1 -BaseUrl https://test.andreaslop.nl -ImagesDirectory K:\Development\SlpSoftware\Projects\AndreaSlopFotografie\web\src\assets
.EXAMPLE
./scripts/Seed-Hero.ps1 -BaseUrl https://test.slpsoftware.nl -SeedFile ./scripts/hero-sls.json
#>
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)] [string] $BaseUrl,
[string] $SeedFile,
[string] $ImagesDirectory,
[string] $Email,
[switch] $Force
)
$ErrorActionPreference = 'Stop'
# $PSScriptRoot is empty in a param default under Windows PowerShell 5.1, so it is read here.
$here = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
if (-not $SeedFile) { $SeedFile = Join-Path $here 'hero-asf.json' }
$BaseUrl = $BaseUrl.TrimEnd('/')
$api = "$BaseUrl/api/v1"
$seed = Get-Content -LiteralPath $SeedFile -Raw -Encoding UTF8 | ConvertFrom-Json
if ([string]::IsNullOrWhiteSpace($seed.title) -or $seed.title -like 'TODO*') { throw "The seed has no title (or it is still TODO)." }
$slides = @($seed.slides | Where-Object { $_ })
if ($slides.Count -gt 0) {
if (-not $ImagesDirectory) { throw 'The seed has slides: give -ImagesDirectory (the folder with the photos).' }
foreach ($s in $slides) {
$path = Join-Path $ImagesDirectory $s.file
if (-not (Test-Path -LiteralPath $path)) { throw "Photo not found: $path" }
if ([string]::IsNullOrWhiteSpace($s.alt) -and -not $s.decorative) { throw "Slide '$($s.file)' has no alt text and is not decorative." }
}
}
if ($WhatIfPreference) {
Write-Host "Would save the hero '$($seed.title -replace "`n", ' / ')' on $BaseUrl with $($slides.Count) slide(s):"
$slides | ForEach-Object { Write-Host " $($_.file) focus $($_.focus.x),$($_.focus.y) alt: $($_.alt)" }
return
}
if (-not $Email) { $Email = Read-Host 'Admin e-mail' }
$secure = Read-Host "Password for $Email" -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try {
$plain = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
$body = @{ email = $Email; password = $plain } | ConvertTo-Json -Compress
$login = Invoke-RestMethod -Method Post -Uri "$api/auth/login" -ContentType 'application/json' -Body $body
}
finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$plain = $null; $body = $null
}
$token = $login.accessToken
$headers = @{ Authorization = "Bearer $token" }
$current = Invoke-RestMethod -Method Get -Uri "$api/hero/all" -Headers $headers
if ($current.id -and -not $Force) {
Write-Host "skip a hero already exists on $BaseUrl (use -Force to replace it)"
return
}
Add-Type -AssemblyName System.Net.Http
function Send-Photo([string] $path) {
$client = [System.Net.Http.HttpClient]::new()
try {
$client.DefaultRequestHeaders.Authorization = [System.Net.Http.Headers.AuthenticationHeaderValue]::new('Bearer', $token)
$form = [System.Net.Http.MultipartFormDataContent]::new()
$bytes = [System.IO.File]::ReadAllBytes($path)
$content = [System.Net.Http.ByteArrayContent]::new($bytes)
$form.Add($content, 'file', [System.IO.Path]::GetFileName($path))
$response = $client.PostAsync("$api/hero/images", $form).GetAwaiter().GetResult()
$text = $response.Content.ReadAsStringAsync().GetAwaiter().GetResult()
if (-not $response.IsSuccessStatusCode) { throw "Upload of '$path' failed ($([int]$response.StatusCode)): $text" }
return ($text | ConvertFrom-Json)
}
finally { $client.Dispose() }
}
$requestSlides = @()
foreach ($s in $slides) {
$image = Send-Photo (Join-Path $ImagesDirectory $s.file)
Write-Host "upload $($s.file) -> image $($image.id)"
if ($s.focus) {
$focus = @{ focus = @{ x = [double]$s.focus.x; y = [double]$s.focus.y; zoom = 1.0 }; wide = $null; tall = $null } | ConvertTo-Json -Depth 5
$null = Invoke-RestMethod -Method Put -Uri "$api/hero/images/$($image.id)/focus" -Headers $headers -ContentType 'application/json' -Body $focus
Write-Host "focus $($s.file) at $($s.focus.x), $($s.focus.y)"
}
$requestSlides += [ordered]@{ imageId = $image.id; alt = $(if ($s.decorative) { $null } else { $s.alt }); decorative = [bool]$s.decorative; isActive = $true }
}
$payload = [ordered]@{
title = $seed.title
tagline = $(if ($seed.tagline) { $seed.tagline } else { $null })
lead = $(if ($seed.lead) { $seed.lead } else { $null })
display = $(if ($seed.display) { $seed.display } else { 'single' })
buttons = @($seed.buttons | Where-Object { $_ } | ForEach-Object { [ordered]@{ label = $_.label; target = $_.target } })
isActive = $true
startsAt = $null
endsAt = $null
slides = $requestSlides
} | ConvertTo-Json -Depth 6
try {
$saved = Invoke-RestMethod -Method Put -Uri "$api/hero" -Headers $headers -ContentType 'application/json; charset=utf-8' -Body ([Text.Encoding]::UTF8.GetBytes($payload))
Write-Host "saved hero $($saved.id) with $($saved.slides.Count) slide(s); live: $($saved.isLive)"
}
catch {
Write-Error "Saving the hero failed: $($_.Exception.Message) $($_.ErrorDetails.Message)"
}
+87
View File
@@ -0,0 +1,87 @@
{
"note": "Seed of the ASF hero for the TEST CMS (ASF commit 13f78c4, web/contract/host-injection/hero/seed.json). Photos: the existing exports in the website repository (web/src/assets, hero-1.jpg to hero-8.jpg); never upscaled. The focus points are a first estimate by looking at the photos (x and y from the top left, 0 to 1); Bryan adjusts them in the admin.",
"display": "slideshow",
"title": "Andrea Slop",
"tagline": "Lifestyle fotograaf · Huizen",
"lead": null,
"buttons": [
{
"label": "Lees meer",
"target": "/over-mij"
}
],
"slides": [
{
"file": "hero-8.jpg",
"alt": "Zwangerschapsfoto in de duinen",
"decorative": false,
"focus": {
"x": 0.5,
"y": 0.55
}
},
{
"file": "hero-7.jpg",
"alt": "Knusse newbornfoto met de familie",
"decorative": false,
"focus": {
"x": 0.45,
"y": 0.5
}
},
{
"file": "hero-1.jpg",
"alt": "Lifestyle fotografie",
"decorative": false,
"focus": {
"x": 0.55,
"y": 0.6
}
},
{
"file": "hero-2.jpg",
"alt": "Zwangerschapsshoot in de buitenlucht",
"decorative": false,
"focus": {
"x": 0.45,
"y": 0.45
}
},
{
"file": "hero-3.jpg",
"alt": "Newbornshoot van een pasgeboren baby",
"decorative": false,
"focus": {
"x": 0.45,
"y": 0.4
}
},
{
"file": "hero-4.jpg",
"alt": "Spontaan portret buiten",
"decorative": false,
"focus": {
"x": 0.45,
"y": 0.35
}
},
{
"file": "hero-5.jpg",
"alt": "Natuurlijke lifestylefoto",
"decorative": false,
"focus": {
"x": 0.5,
"y": 0.55
}
},
{
"file": "hero-6.jpg",
"alt": "Portret in de natuur",
"decorative": false,
"focus": {
"x": 0.5,
"y": 0.35
}
}
]
}
+18
View File
@@ -0,0 +1,18 @@
{
"note": "Seed of the SLP Software hero for the TEST CMS: the current texts, unchanged (Bryan, 2026-11-16). The small line 'Web & .NET development' and the code line stay fixed text in the SLP website. The title is one field with line breaks; the website derives the screen-reader title from the lines.",
"display": "single",
"title": "Websites,\napps\n& meer.",
"tagline": null,
"lead": "Bij SLP Software kun je terecht voor maatwerk oplossingen. Of het nou gaat om een website, cms of app: wij bouwen het allemaal. Voor ondernemers die geen verrassingen willen — niet in de code, niet op de factuur.",
"buttons": [
{
"label": "Bekijk pakketten",
"target": "#pakketten"
},
{
"label": "Plan een gesprek",
"target": "#contact"
}
],
"slides": []
}
+9 -2
View File
@@ -50,6 +50,13 @@ banner="$(status_of '/api/v1/offerings/banner')"
if [ "$banner" = "200" ] || [ "$banner" = "204" ]; then pass "public banner (/api/v1/offerings/banner -> $banner)"; else fail "public banner (-> $banner, expected 200 or 204)"; fi
expect_status /api/v1/offerings/all 401 "the administrator list is protected"
# The hero: 204 = no hero to show (the website keeps its own), 200 = there is one; the management routes are protected and
# the media endpoint answers a plain 404 for something that is not stored.
hero="$(status_of '/api/v1/hero')"
if [ "$hero" = "200" ] || [ "$hero" = "204" ]; then pass "public hero (/api/v1/hero -> $hero)"; else fail "public hero (-> $hero, expected 200 or 204)"; fi
expect_status /api/v1/hero/all 401 "the hero management read is protected"
expect_status /media/hero/0123456789abcdef/wide-960.webp 404 "media that is not stored is a plain 404"
# A test host is never indexed.
expect_header / X-Robots-Tag noindex "noindex on the website"
expect_body /robots.txt "Disallow: /" "robots.txt disallows everything"
@@ -75,11 +82,11 @@ fi
case "$profile" in
sls-test)
for m in Identity Availability Offerings Contact Master; do expect_module "$m"; done
for m in Identity Availability Offerings Contact Hero Master; do expect_module "$m"; done
expect_status /sitemap.xml 404 "no sitemap on a test host"
;;
asf-test)
for m in Identity Availability Offerings Contact; do expect_module "$m"; done
for m in Identity Availability Offerings Contact Hero; do expect_module "$m"; done
expect_no_module Master
# Prerendered website: an unknown path is a real 404 (an SPA would answer 200).
expect_status /smoke-test-path-that-does-not-exist 404 "unknown website path is a 404"