Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/docs-validate-nav-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ jobs:
run: |
npm install

- name: Check that all files are listed in nav.js
working-directory: docs
run: |
cp docs/nav.js docs/nav.mjs
find docs -name '*.md' | sed 's!^docs/!!' > scripts/docs-files.txt
node scripts/checkNav.mjs docs-files.txt

- name: Backup existing nav.js
working-directory: docs
run: |
mv docs/nav.js docs/nav.js.original
cp docs/nav.js docs/nav.js.original

- name: Build nav.ts
working-directory: docs
Expand All @@ -39,9 +46,3 @@ jobs:
working-directory: docs
run: |
diff -q docs/nav.js docs/nav.js.original || (echo "Generated nav.js differs from committed version. Run 'npm run build' and commit the updated file." && exit 1)

- name: Restore original nav.js
working-directory: docs
if: success() || failure()
run: |
mv docs/nav.js.original docs/nav.js
Comment thread
bfops marked this conversation as resolved.
54 changes: 54 additions & 0 deletions docs/scripts/checkNav.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node

import fs from 'fs';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const navPath = '../docs/nav.mjs';

const mdListPath = process.argv[2];
if (!mdListPath) {
console.error('Usage: node checkNav.mjs <md-list-file>');
process.exit(1);
}

const navFile = path.resolve(__dirname, navPath);
const nav = await import(pathToFileURL(navFile).href).then(mod => mod.default);

const extractPathsFromNav = (items) =>
items.filter(item => item.type === 'page').map(page => page.path);

const navPaths = extractPathsFromNav(nav.items);
const navPathSet = new Set(navPaths);

const expectedMdPaths = fs.readFileSync(path.resolve(__dirname, mdListPath), 'utf8')
.split('\n')
.map(line => line.trim())
.filter(Boolean);
const expectedPathSet = new Set(expectedMdPaths);

const missingInNav = expectedMdPaths.filter(p => !navPathSet.has(p));
const extraInNav = navPaths.filter(p => !expectedPathSet.has(p));

let failed = false;

if (missingInNav.length > 0) {
console.error('❌ New docs added missing from nav:');
missingInNav.forEach(p => console.error(`- ${p}`));
failed = true;
}

if (extraInNav.length > 0) {
console.error('❌ Files listed in nav but not found on filesystem:');
extraInNav.forEach(p => console.error(`- ${p}`));
failed = true;
}

if (!failed) {
console.log('✅ nav list matches filesystem.');
} else {
process.exit(1);
}
Loading