- html-validate su tutte le pagine; linkinator su astro preview (link, asset, CSS e ancore), con modalità --external per i siti esterni - e2e Playwright: struttura e metadati di ogni pagina, 404, navigazione, sottomenu, menu mobile, ancore del vecchio sito, nessuna richiesta esterna, nessun cookie, localStorage vuoto, mappa solo dopo il clic, funzionamento senza JavaScript, modulo di contatto - a11y: axe su tutte le pagine a 1440 e 390 px e negli stati interattivi, tastiera (skip link, sottomenu, menu mobile), focus visibile, testo al 200 %, reflow a 320 px, movimento ridotto - check-compliance.mjs: P.IVA, link legali, risorse sicure, segnaposto, JSON-LD, sitemap, robots, .htaccess, badge e servizi, uso di «commercialista», riferimento L. 4/2013, budget - fix: punti di interruzione in em, focus ciclico nel menu mobile, rel="noopener" sui link esterni del Markdown, numeri di telefono non spezzabili Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016zJ9ZWGKvoKoxYwbmnRKdJ
75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Controllo dei link (brief §11.8) con linkinator sul sito servito da `astro preview`.
|
|
*
|
|
* npm run test:links link interni, immagini, asset, CSS e ancore (#…): bloccante
|
|
* npm run test:links -- --external anche i link verso siti esterni (da eseguire prima di un
|
|
* rilascio; dipende dalla rete)
|
|
*
|
|
* Le pagine di partenza sono lette dalla sitemap generata (più 404 e pagina di conferma).
|
|
*/
|
|
import { resolve } from 'node:path';
|
|
import { LinkChecker, LinkState } from 'linkinator';
|
|
import { EXTRA_PAGES, readSitemapPaths } from './lib/pages.mjs';
|
|
import { root, startPreview } from './lib/preview-server.mjs';
|
|
|
|
const external = process.argv.includes('--external');
|
|
const dist = resolve(root, 'dist');
|
|
const seeds = [...readSitemapPaths(dist), ...EXTRA_PAGES];
|
|
|
|
const server = await startPreview({ port: 4323 });
|
|
const base = server.base;
|
|
let exitCode = 0;
|
|
|
|
try {
|
|
const checker = new LinkChecker();
|
|
const result = await checker.check({
|
|
path: seeds.map((p) => base + p),
|
|
recurse: true,
|
|
concurrency: external ? 4 : 10,
|
|
timeout: external ? 20_000 : 10_000,
|
|
checkCss: true,
|
|
checkFragments: true,
|
|
retryErrors: external,
|
|
retryErrorsCount: 2,
|
|
linksToSkip: async (link) => {
|
|
if (link.startsWith(base)) return false;
|
|
if (!/^https?:\/\//.test(link)) return true; // mailto:, tel:, data:
|
|
return !external;
|
|
},
|
|
// Alcuni siti istituzionali rifiutano i controlli automatici: segnalati come avviso.
|
|
statusCodes: external
|
|
? { 401: 'warn', 403: 'warn', 405: 'warn', 429: 'warn', 999: 'warn' }
|
|
: {},
|
|
});
|
|
|
|
const checked = result.links.filter((l) => l.state !== LinkState.SKIPPED);
|
|
const broken = result.links.filter((l) => l.state === LinkState.BROKEN);
|
|
const internal = checked.filter((l) => l.url.startsWith(base));
|
|
const outside = checked.filter((l) => !l.url.startsWith(base));
|
|
const show = (u) => (u ?? '').replace(base, '');
|
|
|
|
console.log(
|
|
`Link controllati: ${internal.length} interni${external ? `, ${outside.length} esterni` : ''} ` +
|
|
`(partenza da ${seeds.length} pagine).`,
|
|
);
|
|
if (!external)
|
|
console.log('Link esterni non controllati: usa `npm run test:links -- --external`.');
|
|
|
|
if (broken.length > 0) {
|
|
exitCode = 1;
|
|
console.error(`\n✘ ${broken.length} link non funzionanti:`);
|
|
for (const l of broken) {
|
|
console.error(
|
|
` - ${show(l.url)} (stato ${l.status ?? 'nessuna risposta'}) nella pagina ${show(l.parent)}`,
|
|
);
|
|
}
|
|
} else {
|
|
console.log('✔ Nessun link non funzionante.');
|
|
}
|
|
} finally {
|
|
await server.stop();
|
|
}
|
|
|
|
process.exit(exitCode);
|