// Check generated HTML, so Markdown links and MDX components are both covered.
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('../dist/', import.meta.url));
if (!existsSync(root)) throw new Error('Missing dist/. Run npm run build first.');
const origin = 'https://docs.simba-robotics.com';
const files = [];
function walk(dir) {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name);
if (entry.isDirectory()) walk(path);
else files.push(path);
}
}
walk(root);
const pages = new Map(files.filter((path) => path.endsWith('.html'))
.map((path) => [path, readFileSync(path, 'utf8')]));
const errors = [];
let checked = 0;
let diagrams = 0;
for (const [path, html] of pages) {
const page = relative(root, path).split(sep).join('/');
const base = new URL(page.replace(/index\.html$/, ''), origin);
if (html.includes('class="katex-error"')) errors.push(`${page}: invalid math`);
if (/