import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; import path from 'node:path'; import vm from 'node:vm'; import { fileURLToPath } from 'node:url'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const PUBLIC = path.join(ROOT, 'public'); const requested = new Set(process.argv.slice(2)); const wants = (suite) => requested.size === 0 || requested.has('all') || requested.has(suite); const failures = []; function read(relativePath) { return readFileSync(path.join(ROOT, relativePath), 'utf8'); } function visibleText(html) { return html .replace(//gi, ' ') .replace(//gi, ' ') .replace(//gi, ' ') .replace(//gi, ' ') .replace(/<[^>]+>/g, ' ') .replace(/&[a-z0-9#]+;/gi, ' ') .replace(/\s+/g, ' ') .trim(); } function visibleMainText(html) { const main = html.match(//i); return main ? visibleText(main[0]) : ''; } function visibleWordCount(html) { const text = visibleMainText(html); return text ? text.split(' ').length : 0; } function pageHtml(file) { return read(`public/${file}`); } function loadConfig() { const context = { window: {} }; vm.createContext(context); vm.runInContext(read('public/custom/seo-config.js'), context); return context.window.SEO_CONFIG; } function count(text, pattern) { return (text.match(pattern) || []).length; } function htmlEscape(value) { return String(value) .replace(/&/g, '&') .replace(/"/g, '"') .replace(//g, '>'); } function check(name, fn) { try { fn(); console.log(`PASS ${name}`); } catch (error) { failures.push(`${name}: ${error.message}`); console.error(`FAIL ${name}: ${error.message}`); } } function bakeSeo() { return execFileSync(process.execPath, ['scripts/bake-seo.mjs'], { cwd: ROOT, encoding: 'utf8', stdio: 'pipe' }); } function snapshotTopLevelHtml() { return readdirSync(PUBLIC) .filter((name) => name.endsWith('.html')) .sort() .map((name) => [name, readFileSync(path.join(PUBLIC, name), 'utf8')]); } if (wants('core')) { const config = loadConfig(); const cities = ['Hamburg', 'Hannover', 'Wolfsburg', 'Uelzen', 'Celle', 'Lüneburg']; check('Geschäftsort ist Ebstorf', () => { assert.equal(config.BUSINESS.addressLocality, 'Ebstorf'); }); check('alle sechs Sportregionen sind zentral gepflegt', () => { assert.deepEqual(Array.from(config.BUSINESS.areaServed), cities); }); check('sichtbare Wortzahl berücksichtigt nur main', () => { const html = '
Eins zwei drei
Vier fünf
'; assert.equal(visibleWordCount(html), 3); }); check('crawlbare Seiten behaupten keinen Standort Uelzen', () => { for (const urlPath of Object.keys(config.PAGES)) { const file = urlPath === '/' ? 'index.html' : `${urlPath.slice(1)}.html`; const html = pageHtml(file); if (/]*\bnoindex\b/i.test(html)) continue; assert.doesNotMatch( html, /(?:Leon Tonhäuser|Sportfotograf(?:ie)?(?: von Leon Tonhäuser)?) aus Uelzen/i, file ); } }); check('Sportseite hat seitenspezifische Service-Daten', () => { const page = config.PAGES['/sportfotografie']; assert.equal(page.service.serviceType, 'Sportfotografie'); assert.deepEqual( Array.from(page.service.areaServed, (place) => place.name), cities ); assert.ok(page.jsonld.includes('service')); }); check('Eventseite hat Hamburg und Deutschland als Einsatzgebiet', () => { const page = config.PAGES['/eventfotografie']; assert.deepEqual( JSON.parse(JSON.stringify(page.service.areaServed)), [ { type: 'City', name: 'Hamburg' }, { type: 'Country', name: 'Deutschland' } ] ); assert.ok(page.jsonld.includes('service')); }); check('gebackener Event-Head entspricht der Konfiguration', () => { const page = config.PAGES['/eventfotografie']; const html = read('public/eventfotografie.html'); assert.equal(count(html, //g), 1); assert.equal(count(html, /<meta name="description"/g), 1); assert.ok(html.includes(`<title>${htmlEscape(page.title)}`)); assert.ok(html.includes(`content="${htmlEscape(page.desc)}"`)); assert.ok(html.includes('"serviceType":"Eventfotografie"')); assert.ok(html.includes('"@type":"Country","name":"Deutschland"')); }); check('erneutes SEO-Backen verändert keine Top-Level-HTML-Seite', () => { const before = snapshotTopLevelHtml(); bakeSeo(); assert.deepEqual(snapshotTopLevelHtml(), before); }); check('SEO-Bake meldet übersprungene HTML-Seiten als Fehler', () => { const file = path.join(PUBLIC, 'impressum.html'); const original = readFileSync(file, 'utf8'); let failure; try { writeFileSync(file, original.replace('', '')); try { bakeSeo(); } catch (error) { failure = error; } } finally { writeFileSync(file, original); } assert.ok(failure, 'das Backen muss bei übersprungenen HTML-Seiten fehlschlagen'); assert.match(String(failure.stderr), /kein <\/head> in impressum\.html/); }); } if (wants('sport')) { check('Sportseite hat eindeutigen H1 und Canonical', () => { const html = pageHtml('sportfotografie.html'); assert.equal(count(html, /Sportfotograf für Hamburg und Norddeutschland')); assert.ok(html.includes('')); }); check('Sportseite besitzt substanziellen Inhalt', () => { const words = visibleWordCount(pageHtml('sportfotografie.html')); assert.ok(words >= 500 && words <= 800, `Wortzahl ${words} liegt außerhalb 500–800`); }); check('Sportseite belegt Regionen mit vorhandenen Referenzen', () => { const html = pageHtml('sportfotografie.html'); const visible = visibleMainText(html); assert.ok(visible, 'sichtbarer
-Inhalt fehlt'); for (const href of [ './portfolio-hamburger-sv', './portfolio-fc-st-pauli', './portfolio-hannover-96', './portfolio-svg-lueneburg', './portfolio-nfv-pokalfinale-2026' ]) { assert.ok(html.includes(`href="${href}"`), `${href} fehlt`); } for (const city of ['Hamburg', 'Hannover', 'Wolfsburg', 'Uelzen', 'Celle', 'Lüneburg']) { assert.ok(visible.includes(city), `${city} fehlt im sichtbaren main-Inhalt`); } }); check('Sportseite hat Service-Schema und Kontakt-CTA', () => { const html = pageHtml('sportfotografie.html'); assert.ok(html.includes('"serviceType":"Sportfotografie"')); assert.ok(html.includes('href="./kontakt"')); }); } if (wants('event')) { check('Event-Nutzen und Referenzen können nicht nur in Metadaten stehen', () => { const metadataOnly = pageHtml('eventfotografie.html') .replace(//i, '
Ohne die geforderten Begriffe.
'); const visible = visibleText(metadataOnly); for (const term of ['Hamburg', 'deutschlandweit', 'PR', 'Social Media', 'YES!CON 2026', 'OMR x yes!wecancer']) { assert.ok(!visible.includes(term), `${term} darf nicht aus Metadaten als sichtbarer Inhalt gelten`); } }); check('Eventseite hat eindeutigen H1 und substanziellen Inhalt', () => { const html = pageHtml('eventfotografie.html'); assert.equal(count(html, /Eventfotograf für Hamburg und deutschlandweite Veranstaltungen')); const words = visibleWordCount(html); assert.ok(words >= 500 && words <= 800, `Wortzahl ${words} liegt außerhalb 500–800`); }); check('Eventseite nennt Nutzen, Referenzen und Deutschland', () => { const html = pageHtml('eventfotografie.html'); const visible = visibleText(html); for (const term of ['Hamburg', 'deutschlandweit', 'PR', 'Social Media', 'YES!CON 2026', 'OMR x yes!wecancer']) { assert.ok(visible.includes(term), `${term} fehlt im sichtbaren Inhalt`); } assert.ok(html.includes('"serviceType":"Eventfotografie"')); assert.ok(html.includes('"@type":"Country","name":"Deutschland"')); }); check('Startseite verlinkt beide Leistungsseiten', () => { const html = pageHtml('index.html'); assert.ok(html.includes('href="./sportfotografie"')); assert.ok(html.includes('href="./eventfotografie"')); }); check('Leistungs-Hub verlinkt beide Leistungsseiten', () => { const html = pageHtml('leistungen.html'); assert.ok(html.includes('href="./sportfotografie"')); assert.ok(html.includes('href="./eventfotografie"')); }); } if (wants('links')) { const sportPages = [ 'portfolio-hamburger-sv.html', 'portfolio-fc-st-pauli.html', 'portfolio-hannover-96.html', 'portfolio-svg-lueneburg.html', 'portfolio-nfv-pokalfinale-2026.html' ]; const eventPages = [ 'portfolio-yes-con-2026.html', 'portfolio-omr-yes-wecancer.html', 'portfolio-abiball.html' ]; check('Sportreferenzen verlinken die Sportseite', () => { for (const file of sportPages) { assert.ok(pageHtml(file).includes('href="./sportfotografie"'), `${file} fehlt`); } }); check('Eventreferenzen verlinken die Eventseite', () => { for (const file of eventPages) { assert.ok(pageHtml(file).includes('href="./eventfotografie"'), `${file} fehlt`); } }); check('Sitemap enthält die Sportseite und aktuelle Hub-Daten', () => { const xml = read('public/sitemap.xml'); assert.equal(count(xml, /https:\/\/leon-tonhaeuser\.de\/sportfotografie<\/loc>/g), 1); for (const url of ['/', '/leistungen', '/eventfotografie', '/sportfotografie']) { const escaped = url === '/' ? '\\/' : url.replace(/\//g, '\\/'); const entry = new RegExp(`https:\\/\\/leon-tonhaeuser\\.de${escaped}<\\/loc>2026-07-30<\\/lastmod>`); assert.ok(entry.test(xml), `${url} hat kein lastmod 2026-07-30`); } }); check('alle konfigurierten Seiten haben genau einen statischen SEO-Block', () => { const config = loadConfig(); for (const [urlPath, page] of Object.entries(config.PAGES)) { const file = urlPath === '/' ? 'index.html' : `${urlPath.slice(1)}.html`; const html = pageHtml(file); assert.equal(count(html, //g), 1, `${file}: Endmarker`); assert.equal(count(html, //g), 1, `${file}: Title`); assert.equal(count(html, /<meta name="description"/g), 1, `${file}: Description`); assert.ok(html.includes(`<title>${htmlEscape(page.title)}`), `${file}: Title-Wert`); } }); check('alle relativen HTML-Links zeigen auf vorhandene Seiten', () => { const files = readdirSync(PUBLIC).filter((file) => file.endsWith('.html')); for (const file of files) { const html = pageHtml(file); const hrefs = Array.from( html.matchAll(/]*\shref="(\.\/[^"#?]*)/g), (match) => match[1] ); for (const href of hrefs) { const clean = decodeURIComponent(href.slice(2)); const target = clean === '' ? 'index.html' : clean.endsWith('.html') ? clean : `${clean}.html`; assert.ok(existsSync(path.join(PUBLIC, target)), `${file} → ${href}`); } } }); } if (wants('syntax')) { check('alle ausführbaren Inline-Skripte der Top-Level-Seiten sind syntaktisch gültig', () => { const files = readdirSync(PUBLIC).filter((file) => file.endsWith('.html')).sort(); for (const file of files) { const html = pageHtml(file); const scripts = Array.from( html.matchAll(/]*)>([\s\S]*?)<\/script>/gi), (match) => ({ attributes: match[1], source: match[2] }) ); for (const [index, script] of scripts.entries()) { if (/\bsrc\s*=/i.test(script.attributes) || /\btype\s*=\s*["']application\/ld\+json["']/i.test(script.attributes)) { continue; } new vm.Script(script.source, { filename: `${file} inline script ${index + 1}` }); } } }); } if (wants('responsive')) { check('Hero-Titel können auf Mobilgeräten lange Wörter umbrechen', () => { const css = read('public/custom/site.css'); const mobileHeroRule = css.match( /@media\s*\(max-width:\s*809\.98px\)\s*\{\s*\.hero-title\s*\{([^}]*)\}\s*\}/ ); assert.ok(mobileHeroRule, 'Mobile .hero-title-Regel fehlt'); assert.match(mobileHeroRule[1], /hyphens:\s*auto;/); assert.match(mobileHeroRule[1], /overflow-wrap:\s*anywhere;/); }); } if (wants('favicon')) { check('alle Top-Level-Seiten deklarieren das SVG-Favicon und den ICO-Fallback', () => { const files = readdirSync(PUBLIC).filter((file) => file.endsWith('.html')).sort(); for (const file of files) { const html = pageHtml(file); assert.match( html, //, `${file}: SVG-Favicon-Link fehlt` ); assert.match( html, //, `${file}: ICO-Fallback-Link fehlt` ); } }); check('Favicon-Dateien enthalten ein kontrastreiches LT-Monogramm', () => { const svgAsset = path.join(PUBLIC, 'assets', 'favicon.svg'); const icoAsset = path.join(PUBLIC, 'favicon.ico'); assert.ok(existsSync(svgAsset), 'public/assets/favicon.svg fehlt'); assert.ok(existsSync(icoAsset), 'public/favicon.ico fehlt'); const svg = read('public/assets/favicon.svg'); assert.match(svg, /viewBox="0 0 64 64"/); assert.match(svg, /aria-label="Leon Tonhäuser"/); assert.match(svg, />LT<\/text>/); }); } if (wants('agb')) { const expectedTitle = 'AGB & Lizenzbedingungen | Leon Tonhäuser'; const expectedDescription = 'Allgemeine Geschäftsbedingungen sowie Nutzungs- und Lizenzbedingungen von Leon Tonhäuser für Fotoaufträge, Bildlizenzen und das Redaktionsportal.'; const headings = [ '1. Anbieter und Geltungsbereich', '2. Vertragsschluss und Kommunikation', '3. Fotoaufträge', '4. Redaktionsportal und Benutzerkonto', '5. Urheberrecht und Umfang der Bildlizenz', '6. Unzulässige Nutzungen und Bearbeitungen', '7. Urhebervermerk und Metadaten', '8. Rechte abgebildeter Personen und redaktioneller Kontext', '9. Vergütung, Nutzungsnachweis und Rechnung', '10. Mitwirkung, Archivierung und Datensicherung', '11. Mängel und Beanstandungen', '12. Haftung', '13. Vertragsdauer und Beendigung des Portalzugangs', '14. Datenschutz', '15. Schlussbestimmungen' ]; check('Nutzungsbedingungen sind nur unter dem freigegebenen Slug vorhanden', () => { assert.ok(existsSync(path.join(PUBLIC, 'nutzungsbedingungen.html')), 'public/nutzungsbedingungen.html fehlt'); assert.ok(!existsSync(path.join(PUBLIC, 'agb.html')), 'public/agb.html darf nicht bleiben'); const pages = loadConfig().PAGES; const page = pages['/nutzungsbedingungen']; assert.ok(page, 'SEO_CONFIG.PAGES[\'/nutzungsbedingungen\'] fehlt'); assert.equal(pages['/agb'], undefined, 'alte /agb-Konfiguration darf nicht bleiben'); assert.equal(page.title, expectedTitle); assert.equal(page.desc, expectedDescription); assert.deepEqual(Array.from(page.jsonld), ['breadcrumb']); assert.ok( pageHtml('nutzungsbedingungen.html').includes('"name":"AGB & Lizenzbedingungen"'), 'gebackener Breadcrumb-Name ist nicht freigegeben' ); }); check('AGB-Seite ist semantisch in 15 Abschnitte gegliedert', () => { const html = pageHtml('nutzungsbedingungen.html'); assert.equal(count(html, /AGB & Lizenzbedingungen')); for (const [index, heading] of headings.entries()) { const section = index + 1; assert.equal(count(html, new RegExp(`id="agb-${section}"`, 'g')), 1, `Abschnitt agb-${section}`); assert.equal(count(html, new RegExp(`href="#agb-${section}"`, 'g')), 1, `Inhaltslink agb-${section}`); assert.ok(html.includes(`

${heading}

`), heading); } }); check('AGB-Seite enthält die freigegebenen Vertragsdaten ohne interne Platzhalter', () => { const html = pageHtml('nutzungsbedingungen.html'); const visible = visibleMainText(html); for (const text of [ 'Leon Tonhäuser | Sportfotografie', 'Tannenworthring 40, 29574 Ebstorf', 'mail@leon-tonhaeuser.de', 'Stand: 11. August 2026', 'Rechnungen sind innerhalb von 14 Kalendertagen ab Zugang ohne Abzug zahlbar', '© Leon Tonhäuser', 'der Sitz des Fotografen ausschließlicher Gerichtsstand' ]) { assert.ok(visible.includes(text), `${text} fehlt`); } assert.ok(html.includes('href="./datenschutz"')); assert.ok(html.includes('href="./impressum"')); assert.doesNotMatch( html, /\[(?:VOLLSTÄNDIGER|ANSCHRIFT|E-MAIL|UST-ID|ORT DES GERICHTSSTANDS|URL)|Arbeitsentwurf|Wichtiger Hinweis|Hinweise für die KI|Verwendete amtliche Grundlagen/i ); }); check('AGB-Seite bietet eine druckfreundliche Ausgabe', () => { const html = pageHtml('nutzungsbedingungen.html'); const css = read('public/custom/site.css'); assert.match(html, /]*\btype="button"[^>]*\bonclick="window\.print\(\)"[^>]*>/); const printRules = css.match(/@media\s+print\s*\{([\s\S]*?)\n\}/); assert.ok(printRules, '@media print fehlt'); assert.match(printRules[1], /\.topbar/); assert.match(printRules[1], /\.dock/); assert.match(printRules[1], /\.footer/); assert.match(printRules[1], /\.agb-drucken/); assert.match(printRules[1], /display:\s*none/); }); check('AGB-H1 bleibt mobil ohne Worttrennung lesbar', () => { const html = pageHtml('nutzungsbedingungen.html'); const css = read('public/custom/site.css'); assert.match(html, //); const mobileTitleRule = css.match( /@media\s*\(max-width:\s*809\.98px\)\s*\{[\s\S]*?\.agb-seite\s+\.hero-title\s*\{([^}]*)\}/ ); assert.ok(mobileTitleRule, 'mobile AGB-H1-Regel fehlt'); assert.match(mobileTitleRule[1], /hyphens:\s*none;/); assert.match(mobileTitleRule[1], /overflow-wrap:\s*normal;/); }); check('jeder vorhandene Top-Level-Footer verlinkt nur den neuen Slug', () => { const files = readdirSync(PUBLIC).filter((file) => file.endsWith('.html')).sort(); let footerCount = 0; for (const file of files) { const footer = pageHtml(file).match(//i); if (!footer) continue; footerCount += 1; assert.equal(count(footer[0], /href="\.\/nutzungsbedingungen"/g), 1, `${file}: Nutzungsbedingungen-Link im Footer`); assert.equal(count(footer[0], /href="\.\/agb"/g), 0, `${file}: alter AGB-Link im Footer`); } assert.ok(footerCount >= 28, `nur ${footerCount} Footer geprüft`); }); check('Kontaktformular verweist unmittelbar auf die AGB', () => { const html = pageHtml('kontakt.html'); const form = html.match(/]*id="kontaktformular"[\s\S]*?<\/form>/i); assert.ok(form, 'Kontaktformular fehlt'); assert.match( form[0], /]*type="submit"[\s\S]*?]*class="kontakt-rechtshinweis"[^>]*>Für geschäftliche Anfragen gelten unsere AGB & Lizenzbedingungen<\/a>\.<\/p>/ ); }); check('Sitemap enthält nur den neuen Slug mit aktuellem Versionsdatum', () => { const xml = read('public/sitemap.xml'); assert.equal(count(xml, /https:\/\/leon-tonhaeuser\.de\/nutzungsbedingungen<\/loc>/g), 1); assert.doesNotMatch(xml, /https:\/\/leon-tonhaeuser\.de\/agb<\/loc>/); assert.match( xml, /https:\/\/leon-tonhaeuser\.de\/nutzungsbedingungen<\/loc>2026-08-11<\/lastmod>yearly<\/changefreq>0\.2<\/priority>/ ); }); } if (failures.length) { console.error(`\n${failures.length} Prüfung(en) fehlgeschlagen.`); process.exit(1); } console.log('\nAlle angeforderten SEO-Prüfungen sind grün.');