diff --git a/scripts/bake-seo.mjs b/scripts/bake-seo.mjs
index 6b6a603..1d226a0 100644
--- a/scripts/bake-seo.mjs
+++ b/scripts/bake-seo.mjs
@@ -109,6 +109,7 @@ function buildBlock(p) {
}
let n = 0;
+let skipped = 0;
for (const f of readdirSync(PUB).filter((x) => x.endsWith('.html'))) {
const fp = path.join(PUB, f);
const p = f === 'index.html' ? '/' : '/' + f.replace(/\.html$/, '');
@@ -117,6 +118,7 @@ for (const f of readdirSync(PUB).filter((x) => x.endsWith('.html'))) {
if (page.title) {
if (!/
[\s\S]*?<\/title>/i.test(html)) {
console.warn('kein in', f);
+ skipped++;
continue;
}
html = html.replace(
@@ -134,9 +136,13 @@ for (const f of readdirSync(PUB).filter((x) => x.endsWith('.html'))) {
}
const re = new RegExp('[\\t ]*' + reEsc(BEGIN) + '[\\s\\S]*?' + reEsc(END) + '\\n?');
html = html.replace(re, '');
- if (!html.includes('')) { console.warn('kein in', f); continue; }
+ if (!html.includes('')) { console.warn('kein in', f); skipped++; continue; }
html = html.replace('', buildBlock(p) + '\n');
writeFileSync(fp, html);
n++;
}
console.log(`Gebacken: ${n} Seiten`);
+if (skipped) {
+ console.error(`${skipped} Seite(n) übersprungen.`);
+ process.exitCode = 1;
+}
diff --git a/scripts/check-seo.mjs b/scripts/check-seo.mjs
index 831e946..58a28d1 100644
--- a/scripts/check-seo.mjs
+++ b/scripts/check-seo.mjs
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
-import { existsSync, readFileSync, readdirSync } from 'node:fs';
+import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import vm from 'node:vm';
import { fileURLToPath } from 'node:url';
@@ -45,12 +45,20 @@ function check(name, fn) {
}
function bakeSeo() {
- execFileSync(process.execPath, ['scripts/bake-seo.mjs'], {
+ 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'];
@@ -96,10 +104,28 @@ if (wants('core')) {
assert.ok(html.includes('"@type":"Country","name":"Deutschland"'));
});
- check('erneutes SEO-Backen verändert den Event-Head nicht', () => {
- const before = read('public/eventfotografie.html');
+ check('erneutes SEO-Backen verändert keine Top-Level-HTML-Seite', () => {
+ const before = snapshotTopLevelHtml();
bakeSeo();
- assert.equal(read('public/eventfotografie.html'), before);
+ assert.deepEqual(snapshotTopLevelHtml(), before);
+ });
+
+ check('SEO-Bake meldet übersprungene HTML-Seiten als Fehler', () => {
+ const file = path.join(PUBLIC, 'blog.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 blog\.html/);
});
}