feat: regionale SEO-Daten zentralisieren
This commit is contained in:
1 parent
e5b4903492
commit
1131ca5f81
31 files changed
+300
-131
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync, readFileSync, readdirSync } 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 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, '<')
|
||||
.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}`);
|
||||
}
|
||||
}
|
||||
|
||||
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('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, /<title>/g), 1);
|
||||
assert.equal(count(html, /<meta name="description"/g), 1);
|
||||
assert.ok(html.includes(`<title>${htmlEscape(page.title)}</title>`));
|
||||
assert.ok(html.includes(`content="${htmlEscape(page.desc)}"`));
|
||||
assert.ok(html.includes('"serviceType":"Eventfotografie"'));
|
||||
assert.ok(html.includes('"@type":"Country","name":"Deutschland"'));
|
||||
});
|
||||
}
|
||||
|
||||
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.');
|
||||
Reference in new issue
Block a user