sitecheckultra 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -6
- package/bin/sitecheckultra.js +65 -12
- package/lib/analyzer.js +162 -11
- package/lib/crawl-error.js +171 -0
- package/lib/crawler.js +297 -186
- package/lib/exporter.js +126 -110
- package/lib/page-preview.js +311 -0
- package/lib/scorer.js +50 -17
- package/package.json +7 -7
- package/public/app.js +490 -58
- package/public/index.html +27 -9
- package/public/styles.css +138 -1
- package/server.js +66 -2
package/lib/exporter.js
CHANGED
|
@@ -55,16 +55,35 @@ export function formatNumberedOutline(headings = []) {
|
|
|
55
55
|
.join(' | ');
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
function parseColumnFilter(columns) {
|
|
59
|
+
if (!columns) return null;
|
|
60
|
+
if (columns instanceof Set) return columns.size > 0 ? columns : null;
|
|
61
|
+
if (Array.isArray(columns)) return columns.length > 0 ? new Set(columns) : null;
|
|
62
|
+
if (typeof columns === 'string') {
|
|
63
|
+
const ids = columns.split(',').map((s) => s.trim()).filter(Boolean);
|
|
64
|
+
return ids.length > 0 ? new Set(ids) : null;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function buildIndividualHeadingsMatrixSheet(crawl, options = {}) {
|
|
70
|
+
const colFilter = parseColumnFilter(options.columns);
|
|
59
71
|
const { levels, maxByLevel } = getHeadingSlotSummary(crawl, 30);
|
|
60
72
|
const slotDefs = [];
|
|
61
73
|
for (const lvl of levels) {
|
|
62
74
|
const count = maxByLevel.get(lvl) || 0;
|
|
63
75
|
for (let idx = 1; idx <= count; idx++) {
|
|
64
|
-
|
|
76
|
+
const id = `h${lvl}_${idx}`;
|
|
77
|
+
if (colFilter && !colFilter.has(id)) continue;
|
|
78
|
+
slotDefs.push({ id, level: lvl, index: idx, header: `${idx}. H${lvl}` });
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
81
|
|
|
82
|
+
// When filtering and no individual H slots are visible, skip this sheet.
|
|
83
|
+
if (colFilter && slotDefs.length === 0) {
|
|
84
|
+
return { name: 'Einzel-H-Spalten', headers: [], rows: [], skip: true };
|
|
85
|
+
}
|
|
86
|
+
|
|
68
87
|
const headers = ['Seite URL', 'Real Path', 'Status', ...slotDefs.map((s) => s.header)];
|
|
69
88
|
const rows = (crawl.pages || []).map((p) => {
|
|
70
89
|
const byLevel = new Map();
|
|
@@ -95,7 +114,7 @@ export function buildAuditSheet(crawl) {
|
|
|
95
114
|
'Hygiene (15%)',
|
|
96
115
|
'Speed (15%)',
|
|
97
116
|
'Mobile (15%)',
|
|
98
|
-
'WCAG (15%)',
|
|
117
|
+
'WCAG 2.2 (15%)',
|
|
99
118
|
'Kritisch',
|
|
100
119
|
'Warnungen',
|
|
101
120
|
'Kurz-Begründung',
|
|
@@ -130,107 +149,99 @@ export function buildAuditSheet(crawl) {
|
|
|
130
149
|
return { name: 'Audit Score & Begründung', headers, rows };
|
|
131
150
|
}
|
|
132
151
|
|
|
133
|
-
export
|
|
152
|
+
/** Build export column defs aligned with UI TABLE_COLUMNS ids (public/app.js). */
|
|
153
|
+
function buildPagesColumnDefs(crawl, maxLvl) {
|
|
154
|
+
const robotsStatus = (p) =>
|
|
155
|
+
p.blockedByRobotsTxt
|
|
156
|
+
? `Blockiert (HTTP ${p.robotsTxtStatus ?? crawl.robotsTxtStatus ?? ''})`
|
|
157
|
+
: (p.robotsTxtStatus === 404 || crawl.robotsTxtStatus === 404)
|
|
158
|
+
? 'Keine (404)'
|
|
159
|
+
: ((p.robotsTxtStatus ?? crawl.robotsTxtStatus) >= 400)
|
|
160
|
+
? `Fehler (${p.robotsTxtStatus ?? crawl.robotsTxtStatus})`
|
|
161
|
+
: `Erlaubt (HTTP ${p.robotsTxtStatus ?? crawl.robotsTxtStatus ?? 200})`;
|
|
162
|
+
|
|
163
|
+
const byLevel = (p, lvl) =>
|
|
164
|
+
(p.headings || [])
|
|
165
|
+
.filter((h) => h.level === lvl)
|
|
166
|
+
.map((h, i) => `${i + 1}. H${lvl}: ${h.text || '(leer)'}`)
|
|
167
|
+
.join(' | ');
|
|
168
|
+
|
|
169
|
+
const auditOf = (p) => {
|
|
170
|
+
const a = p.audit || { overall: 0, grade: '–', categories: {}, summary: '' };
|
|
171
|
+
const cats = { seo: 0, aeo: 0, hygiene: 0, speed: 0, mobile: 0, wcag: 0, ...(a.categories || {}) };
|
|
172
|
+
return { a, cats };
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const defs = [
|
|
176
|
+
{ id: 'site', header: 'Seite (Title)', value: (p) => p.title || '' },
|
|
177
|
+
{ id: 'full_url', header: 'Seite URL (Vollständig)', value: (p) => p.url || '' },
|
|
178
|
+
{ id: 'full_url', header: 'Finale URL', value: (p) => p.finalUrl || p.url || '' },
|
|
179
|
+
{ id: 'path', header: 'Real Path', value: (p) => p.path || '' },
|
|
180
|
+
{ id: 'status', header: 'Status', value: (p) => p.status || 0 },
|
|
181
|
+
{ id: 'audit_score', header: 'Gesamt-Score', value: (p) => auditOf(p).a.overall },
|
|
182
|
+
{ id: 'audit_score', header: 'Note', value: (p) => auditOf(p).a.grade },
|
|
183
|
+
{ id: 'audit_seo', header: 'SEO Score', value: (p) => auditOf(p).cats.seo },
|
|
184
|
+
{ id: 'audit_aeo', header: 'AEO Score', value: (p) => auditOf(p).cats.aeo },
|
|
185
|
+
{ id: 'audit_hygiene', header: 'Hygiene Score', value: (p) => auditOf(p).cats.hygiene },
|
|
186
|
+
{ id: 'audit_speed', header: 'Speed Score', value: (p) => auditOf(p).cats.speed },
|
|
187
|
+
{ id: 'audit_mobile', header: 'Mobile Score', value: (p) => auditOf(p).cats.mobile },
|
|
188
|
+
{ id: 'audit_wcag', header: 'WCAG 2.2 Score', value: (p) => auditOf(p).cats.wcag },
|
|
189
|
+
{ id: 'audit_reason', header: 'Score-Begründung', value: (p) => auditOf(p).a.summary || '' },
|
|
190
|
+
{ id: 'index', header: 'Index', value: (p) => (p.indexable ? 'Index' : 'Noindex') },
|
|
191
|
+
{ id: 'follow', header: 'Follow', value: (p) => (p.followable ? 'Follow' : 'Nofollow') },
|
|
192
|
+
{ id: 'robots_txt', header: 'Robots.txt Status', value: (p) => robotsStatus(p) },
|
|
193
|
+
{ id: 'robots_txt', header: 'Robots.txt Regel', value: (p) => p.robotsDisallowRule || '' },
|
|
194
|
+
{ id: 'sitemap', header: 'Sitemap', value: (p) => (p.inSitemap ? 'Ja' : 'Nein') },
|
|
195
|
+
{ id: 'sitemap_lastmod', header: 'Sitemap Lastmod Status', value: (p) => (!p.inSitemap ? 'Nicht in Sitemap' : (p.sitemapLastmod ? 'Vorhanden' : 'Kein lastmod')) },
|
|
196
|
+
{ id: 'sitemap_lastmod', header: 'Sitemap Lastmod', value: (p) => p.sitemapLastmod || '' },
|
|
197
|
+
{ id: 'canonical', header: 'Canonical', value: (p) => p.canonical || '' },
|
|
198
|
+
{ id: 'canonical', header: 'Canonical Typ', value: (p) => p.canonicalType || '' },
|
|
199
|
+
{ id: 'redirect', header: 'Redirect', value: (p) => (p.hasRedirect ? `${p.redirectStatus} -> ${p.redirectTarget}` : '') },
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
for (let lvl = 1; lvl <= maxLvl; lvl++) {
|
|
203
|
+
defs.push({ id: `h${lvl}`, header: `H${lvl}`, value: (p) => byLevel(p, lvl) });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
defs.push(
|
|
207
|
+
{ id: 'h_outline', header: 'H-Struktur Komplett', value: (p) => formatNumberedOutline(p.headings || []) },
|
|
208
|
+
{ id: 'h_counts', header: 'H-Probleme', value: (p) => (p.headingIssues?.hasIssues ? 'Ja' : 'Nein') },
|
|
209
|
+
{ id: 'meta_title', header: 'Meta Title', value: (p) => p.title || '' },
|
|
210
|
+
{ id: 'meta_desc', header: 'Meta Description', value: (p) => p.metaDescription || '' },
|
|
211
|
+
{ id: 'schema', header: 'Schema', value: (p) => (p.schemaTypes || []).join(', ') },
|
|
212
|
+
{ id: 'tracking', header: 'Tracking', value: (p) => (p.tracking?.detected || []).map((t) => `${t.badge}:${t.name}`).join(', ') },
|
|
213
|
+
{ id: 'links', header: 'Links', value: (p) => p.linkCount || 0 },
|
|
214
|
+
{ id: 'links', header: 'Defekte Links', value: (p) => p.brokenLinksCount || 0 },
|
|
215
|
+
{ id: 'missing_alt', header: 'Bilder ohne Alt', value: (p) => p.imagesMissingAltCount || 0 },
|
|
216
|
+
{ id: 'words', header: 'Wörter', value: (p) => p.wordCount || 0 },
|
|
217
|
+
{ id: 'response_time', header: 'Ladezeit (ms)', value: (p) => p.responseTimeMs || 0 },
|
|
218
|
+
{ id: 'last_modified', header: 'Geändert', value: (p) => p.lastModified || '' },
|
|
219
|
+
{ id: 'note', header: 'Notiz', value: (p) => p.note || '' }
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
return defs;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function buildPagesSheet(crawl, options = {}) {
|
|
134
226
|
ensureCrawlScores(crawl);
|
|
135
227
|
const maxLvl = getMaxHeadingLevel(crawl);
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
'Seite (Title)',
|
|
139
|
-
'Seite URL (Vollständig)',
|
|
140
|
-
'Finale URL',
|
|
141
|
-
'Real Path',
|
|
142
|
-
'Status',
|
|
143
|
-
'Gesamt-Score',
|
|
144
|
-
'Note',
|
|
145
|
-
'SEO Score',
|
|
146
|
-
'AEO Score',
|
|
147
|
-
'Hygiene Score',
|
|
148
|
-
'Speed Score',
|
|
149
|
-
'Mobile Score',
|
|
150
|
-
'WCAG Score',
|
|
151
|
-
'Score-Begründung',
|
|
152
|
-
'Index',
|
|
153
|
-
'Follow',
|
|
154
|
-
'Robots.txt Status',
|
|
155
|
-
'Robots.txt Regel',
|
|
156
|
-
'Sitemap',
|
|
157
|
-
'Sitemap Lastmod Status',
|
|
158
|
-
'Sitemap Lastmod',
|
|
159
|
-
'Canonical',
|
|
160
|
-
'Canonical Typ',
|
|
161
|
-
'Redirect',
|
|
162
|
-
...hHeaders,
|
|
163
|
-
'H-Struktur Komplett',
|
|
164
|
-
'H-Probleme',
|
|
165
|
-
'Meta Description',
|
|
166
|
-
'Schema',
|
|
167
|
-
'Tracking',
|
|
168
|
-
'Links',
|
|
169
|
-
'Defekte Links',
|
|
170
|
-
'Bilder ohne Alt',
|
|
171
|
-
'Wörter',
|
|
172
|
-
'Ladezeit (ms)',
|
|
173
|
-
'Geändert',
|
|
174
|
-
'Notiz'
|
|
175
|
-
];
|
|
228
|
+
const colFilter = parseColumnFilter(options.columns);
|
|
229
|
+
const allDefs = buildPagesColumnDefs(crawl, maxLvl);
|
|
176
230
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
p.finalUrl || p.url || '',
|
|
192
|
-
p.path || '',
|
|
193
|
-
p.status || 0,
|
|
194
|
-
a.overall,
|
|
195
|
-
a.grade,
|
|
196
|
-
cats.seo,
|
|
197
|
-
cats.aeo,
|
|
198
|
-
cats.hygiene,
|
|
199
|
-
cats.speed,
|
|
200
|
-
cats.mobile,
|
|
201
|
-
cats.wcag,
|
|
202
|
-
a.summary || '',
|
|
203
|
-
p.indexable ? 'Index' : 'Noindex',
|
|
204
|
-
p.followable ? 'Follow' : 'Nofollow',
|
|
205
|
-
p.blockedByRobotsTxt
|
|
206
|
-
? `Blockiert (HTTP ${p.robotsTxtStatus ?? crawl.robotsTxtStatus ?? ''})`
|
|
207
|
-
: (p.robotsTxtStatus === 404 || crawl.robotsTxtStatus === 404)
|
|
208
|
-
? 'Keine (404)'
|
|
209
|
-
: ((p.robotsTxtStatus ?? crawl.robotsTxtStatus) >= 400)
|
|
210
|
-
? `Fehler (${p.robotsTxtStatus ?? crawl.robotsTxtStatus})`
|
|
211
|
-
: `Erlaubt (HTTP ${p.robotsTxtStatus ?? crawl.robotsTxtStatus ?? 200})`,
|
|
212
|
-
p.robotsDisallowRule || '',
|
|
213
|
-
p.inSitemap ? 'Ja' : 'Nein',
|
|
214
|
-
!p.inSitemap ? 'Nicht in Sitemap' : (p.sitemapLastmod ? 'Vorhanden' : 'Kein lastmod'),
|
|
215
|
-
p.sitemapLastmod || '',
|
|
216
|
-
p.canonical || '',
|
|
217
|
-
p.canonicalType || '',
|
|
218
|
-
p.hasRedirect ? `${p.redirectStatus} -> ${p.redirectTarget}` : '',
|
|
219
|
-
...hCols,
|
|
220
|
-
fullOutline,
|
|
221
|
-
p.headingIssues?.hasIssues ? 'Ja' : 'Nein',
|
|
222
|
-
p.metaDescription || '',
|
|
223
|
-
(p.schemaTypes || []).join(', '),
|
|
224
|
-
(p.tracking?.detected || []).map((t) => `${t.badge}:${t.name}`).join(', '),
|
|
225
|
-
p.linkCount || 0,
|
|
226
|
-
p.brokenLinksCount || 0,
|
|
227
|
-
p.imagesMissingAltCount || 0,
|
|
228
|
-
p.wordCount || 0,
|
|
229
|
-
p.responseTimeMs || 0,
|
|
230
|
-
p.lastModified || '',
|
|
231
|
-
p.note || ''
|
|
232
|
-
];
|
|
233
|
-
});
|
|
231
|
+
// Without filter: keep legacy columns (exclude meta_title which is UI-only duplicate of site title).
|
|
232
|
+
const defs = colFilter
|
|
233
|
+
? allDefs.filter((d) => colFilter.has(d.id))
|
|
234
|
+
: allDefs.filter((d) => d.id !== 'meta_title');
|
|
235
|
+
|
|
236
|
+
// Fallback: if filter matched no page columns (e.g. only H-slot ids), keep identity columns.
|
|
237
|
+
const activeDefs = defs.length > 0
|
|
238
|
+
? defs
|
|
239
|
+
: colFilter
|
|
240
|
+
? allDefs.filter((d) => d.id === 'full_url' || d.id === 'path' || d.id === 'status')
|
|
241
|
+
: allDefs.filter((d) => d.id !== 'meta_title');
|
|
242
|
+
|
|
243
|
+
const headers = activeDefs.map((d) => d.header);
|
|
244
|
+
const rows = (crawl.pages || []).map((p) => activeDefs.map((d) => d.value(p)));
|
|
234
245
|
|
|
235
246
|
return { name: 'Alle Seiten', headers, rows };
|
|
236
247
|
}
|
|
@@ -305,20 +316,20 @@ export function buildScriptsSheet(crawl) {
|
|
|
305
316
|
return { name: 'Scripts', headers, rows };
|
|
306
317
|
}
|
|
307
318
|
|
|
308
|
-
export function buildCsvContent(crawl, type = 'pages') {
|
|
319
|
+
export function buildCsvContent(crawl, type = 'pages', options = {}) {
|
|
309
320
|
const sheet =
|
|
310
321
|
type === 'audit' ? buildAuditSheet(crawl)
|
|
311
322
|
: type === 'headings' ? buildHeadingsSheet(crawl)
|
|
312
323
|
: type === 'links' ? buildLinksSheet(crawl)
|
|
313
324
|
: type === 'redirects' ? buildRedirectsSheet(crawl)
|
|
314
325
|
: type === 'scripts' ? buildScriptsSheet(crawl)
|
|
315
|
-
: buildPagesSheet(crawl);
|
|
326
|
+
: buildPagesSheet(crawl, options);
|
|
316
327
|
|
|
317
328
|
const allRows = [sheet.headers, ...sheet.rows];
|
|
318
329
|
return '\uFEFF' + allRows.map((r) => r.map(csvEscape).join(';')).join('\r\n');
|
|
319
330
|
}
|
|
320
331
|
|
|
321
|
-
export async function buildExcelBuffer(crawl, type = 'all') {
|
|
332
|
+
export async function buildExcelBuffer(crawl, type = 'all', options = {}) {
|
|
322
333
|
const { default: ExcelJS } = await import('exceljs');
|
|
323
334
|
const workbook = new ExcelJS.Workbook();
|
|
324
335
|
workbook.creator = 'Site Check Ultra';
|
|
@@ -335,10 +346,15 @@ export async function buildExcelBuffer(crawl, type = 'all') {
|
|
|
335
346
|
sheetsToAdd.push(buildRedirectsSheet(crawl));
|
|
336
347
|
} else if (type === 'scripts') {
|
|
337
348
|
sheetsToAdd.push(buildScriptsSheet(crawl));
|
|
349
|
+
} else if (type === 'pages') {
|
|
350
|
+
sheetsToAdd.push(buildPagesSheet(crawl, options));
|
|
351
|
+
const matrix = buildIndividualHeadingsMatrixSheet(crawl, options);
|
|
352
|
+
if (!matrix.skip) sheetsToAdd.push(matrix);
|
|
338
353
|
} else {
|
|
339
354
|
sheetsToAdd.push(buildAuditSheet(crawl));
|
|
340
|
-
sheetsToAdd.push(buildPagesSheet(crawl));
|
|
341
|
-
|
|
355
|
+
sheetsToAdd.push(buildPagesSheet(crawl, options));
|
|
356
|
+
const matrix = buildIndividualHeadingsMatrixSheet(crawl, options);
|
|
357
|
+
if (!matrix.skip) sheetsToAdd.push(matrix);
|
|
342
358
|
sheetsToAdd.push(buildHeadingsSheet(crawl));
|
|
343
359
|
const linksSheet = buildLinksSheet(crawl);
|
|
344
360
|
if (linksSheet.rows.length > 0) sheetsToAdd.push(linksSheet);
|
|
@@ -401,7 +417,7 @@ export function buildHtmlAuditReport(crawl) {
|
|
|
401
417
|
const sum = crawl.auditSummary;
|
|
402
418
|
const host = (crawl.origin || crawl.startUrl || '').replace(/^https?:\/\//i, '');
|
|
403
419
|
const dateStr = new Date(crawl.createdAt || Date.now()).toLocaleString('de-DE');
|
|
404
|
-
const catLabels = { seo: 'SEO', aeo: 'AEO / KI', hygiene: 'Hygiene', speed: 'Speed', mobile: 'Mobile', wcag: 'WCAG' };
|
|
420
|
+
const catLabels = { seo: 'SEO', aeo: 'AEO / KI', hygiene: 'Hygiene', speed: 'Speed', mobile: 'Mobile', wcag: 'WCAG 2.2' };
|
|
405
421
|
|
|
406
422
|
const catCards = [
|
|
407
423
|
{ key: 'seo', title: 'SEO (25 %)', desc: 'Indexierung, Meta-Daten, Canonical, Sitemap, H1, Inhalt', val: sum.categories.seo },
|
|
@@ -409,7 +425,7 @@ export function buildHtmlAuditReport(crawl) {
|
|
|
409
425
|
{ key: 'hygiene', title: 'Hygiene (15 %)', desc: 'H-Hierarchie, Redirect-Ketten, JSON-LD Gültigkeit, Tracking', val: sum.categories.hygiene },
|
|
410
426
|
{ key: 'speed', title: 'Speed (15 %)', desc: 'Antwortzeit (TTFB), HTML-Größe, externe Scripts', val: sum.categories.speed },
|
|
411
427
|
{ key: 'mobile', title: 'Mobile (15 %)', desc: 'Viewport, responsive Bilder, Touch-Icon, Open Graph', val: sum.categories.mobile },
|
|
412
|
-
{ key: 'wcag', title: 'WCAG (15 %)', desc: 'Alt-
|
|
428
|
+
{ key: 'wcag', title: 'WCAG 2.2 (15 %)', desc: 'lang, Alt-Attribute, H-Struktur, Linktexte/Namen, iframe-title, main, tabindex', val: sum.categories.wcag }
|
|
413
429
|
].map((c) => `
|
|
414
430
|
<div class="cat-card">
|
|
415
431
|
<div class="cat-top"><span>${c.title}</span><strong style="color:${scoreColorHex(c.val)}">${c.val} / 100</strong></div>
|
|
@@ -497,7 +513,7 @@ export function buildHtmlAuditReport(crawl) {
|
|
|
497
513
|
<div class="header">
|
|
498
514
|
<div>
|
|
499
515
|
<h1>Site Check Ultra Audit Report – ${escHtml(host)}</h1>
|
|
500
|
-
<div class="sub">Erstellt am ${escHtml(dateStr)} · ${sum.totalPages} geprüfte Seiten · Bewertet nach SEO, AEO/KI, Hygiene, Speed, Mobile & WCAG</div>
|
|
516
|
+
<div class="sub">Erstellt am ${escHtml(dateStr)} · ${sum.totalPages} geprüfte Seiten · Bewertet nach SEO, AEO/KI, Hygiene, Speed, Mobile & WCAG 2.2</div>
|
|
501
517
|
</div>
|
|
502
518
|
<button class="print-btn" onclick="window.print()">Als PDF drucken</button>
|
|
503
519
|
</div>
|
|
@@ -523,7 +539,7 @@ export function buildHtmlAuditReport(crawl) {
|
|
|
523
539
|
<div class="card">
|
|
524
540
|
<h2>Detail-Auswertung aller ${sum.totalPages} Seiten (schwächste zuerst)</h2>
|
|
525
541
|
<table>
|
|
526
|
-
<thead><tr><th>Seite</th><th class="num">Score</th><th class="num">SEO</th><th class="num">AEO</th><th class="num">Hygiene</th><th class="num">Speed</th><th class="num">Mobile</th><th class="num">WCAG</th><th>Begründung im Detail</th></tr></thead>
|
|
542
|
+
<thead><tr><th>Seite</th><th class="num">Score</th><th class="num">SEO</th><th class="num">AEO</th><th class="num">Hygiene</th><th class="num">Speed</th><th class="num">Mobile</th><th class="num">WCAG 2.2</th><th>Begründung im Detail</th></tr></thead>
|
|
527
543
|
<tbody>${pageRows}</tbody>
|
|
528
544
|
</table>
|
|
529
545
|
</div>
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Same-origin HTML preview for missing-alt images.
|
|
3
|
+
* Re-fetches page HTML, rewrites base href so assets resolve, injects a
|
|
4
|
+
* small locator script that scrolls to / highlights the matching <img>.
|
|
5
|
+
*/
|
|
6
|
+
import * as cheerio from 'cheerio';
|
|
7
|
+
import { fetchWithRedirects } from './analyzer.js';
|
|
8
|
+
|
|
9
|
+
const TARGET_SRC_MAX = 4096;
|
|
10
|
+
|
|
11
|
+
function escapeAttr(value) {
|
|
12
|
+
return String(value || '')
|
|
13
|
+
.replace(/&/g, '&')
|
|
14
|
+
.replace(/"/g, '"')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function escapeJsString(value) {
|
|
20
|
+
return JSON.stringify(String(value || ''));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Inject <base>, strip frame/CSP metas that would block our highlighter,
|
|
25
|
+
* and append scroll+flash script for targetSrc.
|
|
26
|
+
*/
|
|
27
|
+
export function buildPagePreviewHtml(html, { baseHref, targetSrc }) {
|
|
28
|
+
const $ = cheerio.load(html || '', { decodeEntities: false });
|
|
29
|
+
|
|
30
|
+
$('meta[http-equiv]').each((_, el) => {
|
|
31
|
+
const v = (($(el).attr('http-equiv') || '')).toLowerCase();
|
|
32
|
+
if (v === 'content-security-policy' || v === 'x-frame-options') {
|
|
33
|
+
$(el).remove();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!$('head').length) {
|
|
38
|
+
$.root().prepend('<head></head>');
|
|
39
|
+
}
|
|
40
|
+
$('base').remove();
|
|
41
|
+
$('head').prepend(`<base href="${escapeAttr(baseHref)}">`);
|
|
42
|
+
|
|
43
|
+
const styleAndScript = `
|
|
44
|
+
<style id="scu-img-preview-style">
|
|
45
|
+
@keyframes scu-img-flash {
|
|
46
|
+
0% { outline-color: transparent; background-color: transparent; box-shadow: none; }
|
|
47
|
+
12% { outline-color: rgba(245, 158, 11, 0.85); background-color: rgba(245, 158, 11, 0.12); box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.2); }
|
|
48
|
+
100% { outline-color: rgba(245, 158, 11, 0.35); background-color: transparent; box-shadow: none; }
|
|
49
|
+
}
|
|
50
|
+
.scu-img-highlight {
|
|
51
|
+
outline: 3px solid rgba(245, 158, 11, 0.8) !important;
|
|
52
|
+
outline-offset: 4px !important;
|
|
53
|
+
border-radius: 2px;
|
|
54
|
+
scroll-margin: 96px;
|
|
55
|
+
animation: scu-img-flash 1.4s ease-out;
|
|
56
|
+
position: relative;
|
|
57
|
+
z-index: 2147483646 !important;
|
|
58
|
+
}
|
|
59
|
+
#scu-img-preview-banner {
|
|
60
|
+
position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
|
|
61
|
+
z-index: 2147483647; max-width: min(520px, calc(100vw - 24px));
|
|
62
|
+
padding: 10px 14px; border-radius: 8px; font: 13px/1.4 system-ui, sans-serif;
|
|
63
|
+
background: #111; color: #f5f5f5; border: 1px solid rgba(245, 158, 11, 0.55);
|
|
64
|
+
box-shadow: 0 8px 28px rgba(0,0,0,0.35); pointer-events: none;
|
|
65
|
+
}
|
|
66
|
+
#scu-img-preview-banner[data-kind="miss"] {
|
|
67
|
+
border-color: rgba(239, 68, 68, 0.55);
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
70
|
+
<script id="scu-img-preview-script">
|
|
71
|
+
(function () {
|
|
72
|
+
var TARGET = ${escapeJsString(targetSrc)};
|
|
73
|
+
var BASE = ${escapeJsString(baseHref)};
|
|
74
|
+
|
|
75
|
+
function absUrl(raw) {
|
|
76
|
+
if (!raw) return '';
|
|
77
|
+
try { return new URL(raw, BASE).href; } catch (e) { return String(raw); }
|
|
78
|
+
}
|
|
79
|
+
function stripQuery(href) {
|
|
80
|
+
try {
|
|
81
|
+
var u = new URL(href);
|
|
82
|
+
u.search = '';
|
|
83
|
+
u.hash = '';
|
|
84
|
+
return u.href;
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return String(href || '').split('#')[0].split('?')[0];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function fileName(href) {
|
|
90
|
+
try {
|
|
91
|
+
var p = new URL(href).pathname;
|
|
92
|
+
return decodeURIComponent(p.split('/').pop() || '');
|
|
93
|
+
} catch (e) {
|
|
94
|
+
var s = String(href || '').split('?')[0].split('#')[0];
|
|
95
|
+
return decodeURIComponent(s.split('/').pop() || '');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function pathKey(href) {
|
|
99
|
+
try { return new URL(href).pathname; } catch (e) {
|
|
100
|
+
return String(href || '').split('?')[0].split('#')[0];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function imgCandidates(img) {
|
|
104
|
+
var attrs = [
|
|
105
|
+
img.getAttribute('src'),
|
|
106
|
+
img.getAttribute('data-src'),
|
|
107
|
+
img.getAttribute('data-lazy-src'),
|
|
108
|
+
img.getAttribute('data-original'),
|
|
109
|
+
img.getAttribute('data-url')
|
|
110
|
+
];
|
|
111
|
+
var srcset = img.getAttribute('srcset') || img.getAttribute('data-srcset') || '';
|
|
112
|
+
if (srcset) {
|
|
113
|
+
var first = srcset.split(',')[0].trim().split(/\\s+/)[0];
|
|
114
|
+
if (first) attrs.push(first);
|
|
115
|
+
}
|
|
116
|
+
var out = [];
|
|
117
|
+
for (var i = 0; i < attrs.length; i++) {
|
|
118
|
+
if (attrs[i]) out.push(absUrl(attrs[i].trim()));
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
function scoreMatch(candidate, targetAbs) {
|
|
123
|
+
if (!candidate || !targetAbs) return 0;
|
|
124
|
+
if (candidate === targetAbs) return 100;
|
|
125
|
+
if (stripQuery(candidate) === stripQuery(targetAbs)) return 90;
|
|
126
|
+
if (pathKey(candidate) && pathKey(candidate) === pathKey(targetAbs)) return 80;
|
|
127
|
+
var a = fileName(candidate);
|
|
128
|
+
var b = fileName(targetAbs);
|
|
129
|
+
if (a && b && a === b) return 60;
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
function findBestImg() {
|
|
133
|
+
var targetAbs = absUrl(TARGET);
|
|
134
|
+
if (!targetAbs || targetAbs.indexOf('data:') === 0) return null;
|
|
135
|
+
var imgs = document.querySelectorAll('img');
|
|
136
|
+
var best = null;
|
|
137
|
+
var bestScore = 0;
|
|
138
|
+
for (var i = 0; i < imgs.length; i++) {
|
|
139
|
+
var cands = imgCandidates(imgs[i]);
|
|
140
|
+
for (var j = 0; j < cands.length; j++) {
|
|
141
|
+
var s = scoreMatch(cands[j], targetAbs);
|
|
142
|
+
if (s > bestScore) {
|
|
143
|
+
bestScore = s;
|
|
144
|
+
best = imgs[i];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return bestScore >= 60 ? best : null;
|
|
149
|
+
}
|
|
150
|
+
function showBanner(kind, text) {
|
|
151
|
+
var el = document.getElementById('scu-img-preview-banner');
|
|
152
|
+
if (!el) {
|
|
153
|
+
el = document.createElement('div');
|
|
154
|
+
el.id = 'scu-img-preview-banner';
|
|
155
|
+
document.documentElement.appendChild(el);
|
|
156
|
+
}
|
|
157
|
+
el.dataset.kind = kind;
|
|
158
|
+
el.textContent = text;
|
|
159
|
+
}
|
|
160
|
+
function notify(found) {
|
|
161
|
+
try {
|
|
162
|
+
parent.postMessage({ type: 'scu-img-preview', found: !!found }, '*');
|
|
163
|
+
} catch (e) { /* ignore */ }
|
|
164
|
+
}
|
|
165
|
+
function run() {
|
|
166
|
+
var img = findBestImg();
|
|
167
|
+
if (!img) {
|
|
168
|
+
showBanner('miss', 'Bild im HTML nicht gefunden (vermutlich lazy/JS-geladen).');
|
|
169
|
+
notify(false);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
img.classList.add('scu-img-highlight');
|
|
173
|
+
try {
|
|
174
|
+
img.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
|
|
175
|
+
} catch (e) {
|
|
176
|
+
img.scrollIntoView(true);
|
|
177
|
+
}
|
|
178
|
+
showBanner('ok', 'Bild auf der Seite markiert');
|
|
179
|
+
notify(true);
|
|
180
|
+
setTimeout(function () {
|
|
181
|
+
img.classList.remove('scu-img-highlight');
|
|
182
|
+
var b = document.getElementById('scu-img-preview-banner');
|
|
183
|
+
if (b) b.remove();
|
|
184
|
+
}, 2200);
|
|
185
|
+
}
|
|
186
|
+
if (document.readyState === 'loading') {
|
|
187
|
+
document.addEventListener('DOMContentLoaded', function () { setTimeout(run, 50); });
|
|
188
|
+
} else {
|
|
189
|
+
setTimeout(run, 50);
|
|
190
|
+
}
|
|
191
|
+
})();
|
|
192
|
+
</script>`;
|
|
193
|
+
|
|
194
|
+
if ($('body').length) {
|
|
195
|
+
$('body').append(styleAndScript);
|
|
196
|
+
} else {
|
|
197
|
+
$.root().append(styleAndScript);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return $.html();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Resolve auth from active crawl memory or Basic Authorization header.
|
|
205
|
+
*/
|
|
206
|
+
export function resolvePreviewAuth(authFromActive, authorizationHeader) {
|
|
207
|
+
if (authFromActive && (authFromActive.username || authFromActive.password)) {
|
|
208
|
+
return {
|
|
209
|
+
username: String(authFromActive.username || ''),
|
|
210
|
+
password: String(authFromActive.password || '')
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const h = String(authorizationHeader || '');
|
|
214
|
+
if (/^Basic\s+/i.test(h)) {
|
|
215
|
+
try {
|
|
216
|
+
const decoded = Buffer.from(h.replace(/^Basic\s+/i, ''), 'base64').toString('utf8');
|
|
217
|
+
const idx = decoded.indexOf(':');
|
|
218
|
+
if (idx >= 0) {
|
|
219
|
+
return {
|
|
220
|
+
username: decoded.slice(0, idx),
|
|
221
|
+
password: decoded.slice(idx + 1)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
} catch {
|
|
225
|
+
/* ignore malformed auth */
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Fetch crawl page HTML and return rewritten preview document.
|
|
233
|
+
* Only allows URLs that belong to the crawl (anti-SSRF).
|
|
234
|
+
*
|
|
235
|
+
* Response shape for callers:
|
|
236
|
+
* { ok: true, html, finalUrl, pageUrl }
|
|
237
|
+
* { ok: false, status, error }
|
|
238
|
+
*/
|
|
239
|
+
export async function createPagePreview({ crawl, pageUrl, targetSrc, auth }) {
|
|
240
|
+
const rawUrl = String(pageUrl || '').trim();
|
|
241
|
+
const rawTarget = String(targetSrc || '').trim().slice(0, TARGET_SRC_MAX);
|
|
242
|
+
|
|
243
|
+
if (!rawUrl) {
|
|
244
|
+
return { ok: false, status: 400, error: 'Query-Parameter url ist erforderlich.' };
|
|
245
|
+
}
|
|
246
|
+
if (!rawTarget) {
|
|
247
|
+
return { ok: false, status: 400, error: 'Query-Parameter targetSrc ist erforderlich.' };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const page = (crawl.pages || []).find(
|
|
251
|
+
(p) => p.url === rawUrl || p.finalUrl === rawUrl
|
|
252
|
+
);
|
|
253
|
+
if (!page) {
|
|
254
|
+
return { ok: false, status: 404, error: 'Seite gehört nicht zu diesem Crawl.' };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const fetchUrl = page.finalUrl || page.url;
|
|
258
|
+
let pageOrigin = '';
|
|
259
|
+
try {
|
|
260
|
+
pageOrigin = new URL(fetchUrl).origin;
|
|
261
|
+
} catch {
|
|
262
|
+
return { ok: false, status: 400, error: 'Ungültige Seiten-URL.' };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (crawl.origin && pageOrigin !== crawl.origin) {
|
|
266
|
+
// Allow same-host final URLs after redirect within crawl pages only (already checked membership)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const fetched = await fetchWithRedirects(fetchUrl, auth, 20000);
|
|
270
|
+
if (fetched.error && !fetched.html) {
|
|
271
|
+
return {
|
|
272
|
+
ok: false,
|
|
273
|
+
status: 502,
|
|
274
|
+
error: `Seite konnte nicht geladen werden: ${fetched.error}`
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
if (!fetched.html) {
|
|
278
|
+
return {
|
|
279
|
+
ok: false,
|
|
280
|
+
status: 502,
|
|
281
|
+
error: 'Antwort enthielt kein HTML (vermutlich kein HTML-Dokument).'
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (fetched.finalStatus === 401 || fetched.finalStatus === 403) {
|
|
285
|
+
return {
|
|
286
|
+
ok: false,
|
|
287
|
+
status: 502,
|
|
288
|
+
error: `Zugriff verweigert (HTTP ${fetched.finalStatus}). Falls die Seite Passwortschutz hat, Auth erneut mitsenden.`
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
if (fetched.finalStatus >= 400) {
|
|
292
|
+
return {
|
|
293
|
+
ok: false,
|
|
294
|
+
status: 502,
|
|
295
|
+
error: `Seite antwortete mit HTTP ${fetched.finalStatus}.`
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const baseHref = fetched.finalUrl || fetchUrl;
|
|
300
|
+
const html = buildPagePreviewHtml(fetched.html, {
|
|
301
|
+
baseHref,
|
|
302
|
+
targetSrc: rawTarget
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
ok: true,
|
|
307
|
+
html,
|
|
308
|
+
finalUrl: baseHref,
|
|
309
|
+
pageUrl: page.url
|
|
310
|
+
};
|
|
311
|
+
}
|