// Checks all internal links and anchors in the built site (dist/). // node scripts/check-links.mjs [distDir] // Exit code 1 if a link points to a missing page or a missing anchor. import { readFileSync, readdirSync, statSync, existsSync } from 'node:fs'; import path from 'node:path'; const dist = path.resolve(process.argv[2] ?? new URL('../dist', import.meta.url).pathname); const base = '/FairMQ'; function walk(dir, out = []) { for (const name of readdirSync(dir)) { const p = path.join(dir, name); if (statSync(p).isDirectory()) walk(p, out); else if (name.endsWith('.html')) out.push(p); } return out; } const pages = walk(dist); const ids = new Map(); const links = []; const idRe = /\sid="([^"]+)"/g; const linkRe = /\s(href|src)="([^"]+)"/g; for (const file of pages) { const html = readFileSync(file, 'utf8'); ids.set(file, new Set([...html.matchAll(idRe)].map((m) => m[1]))); // Skip the content of