Skip to content

Commit f782dab

Browse files
committed
updated script
1 parent 5ced9a3 commit f782dab

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed

.github/workflows/check-breadcrumbs.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"spellcheck:fix": "cspell --words-only --unique \"**/*.mdx\" | sort --ignore-case | uniq > words.txt",
1010
"linkcheck": "lychee --config ./lychee.toml --quiet \"./pages\"",
1111
"breadcrumbs":"npx ts-node --skip-project utils/create-breadcrumbs.ts",
12-
"check-breadcrumbs":"npx ts-node --skip-project utils/check-breadcrumbs.ts",
12+
"check-breadcrumbs":"npx ts-node --skip-project utils/breadcrumbs.ts",
1313
"index:docs": "npx ts-node --skip-project utils/algolia-indexer.ts",
1414
"dev": "next dev",
1515
"build": "next build",

utils/breadcrumbs.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as fs from 'fs/promises';
2+
import * as path from 'path';
3+
4+
const rootDir = path.join(process.cwd(), 'pages');
5+
const errors: string[] = [];
6+
7+
async function checkDirectory(dirPath: string): Promise<void> {
8+
const entries = await fs.readdir(dirPath, { withFileTypes: true });
9+
10+
for (const entry of entries) {
11+
if (entry.name.startsWith('_') || entry.name.startsWith('.')) continue;
12+
13+
const fullPath = path.join(dirPath, entry.name);
14+
15+
if (entry.isDirectory()) {
16+
// Skip if it's the root directory
17+
if (fullPath === rootDir) continue;
18+
19+
// Check if breadcrumb file exists for this directory
20+
const breadcrumbFile = path.join(dirPath, `${entry.name}.mdx`);
21+
try {
22+
await fs.access(breadcrumbFile);
23+
} catch {
24+
const relativePath = path.relative(rootDir, dirPath);
25+
errors.push(`Missing breadcrumb file for directory: ${relativePath}/${entry.name}`);
26+
}
27+
28+
// Recursively check subdirectories
29+
await checkDirectory(fullPath);
30+
}
31+
}
32+
}
33+
34+
async function main() {
35+
try {
36+
await checkDirectory(rootDir);
37+
38+
if (errors.length > 0) {
39+
console.error('Breadcrumb check failed:');
40+
errors.forEach(error => console.error(`- ${error}`));
41+
process.exit(1);
42+
} else {
43+
console.log('All directories have breadcrumb files.');
44+
}
45+
} catch (error) {
46+
console.error('Error checking breadcrumbs:', error);
47+
process.exit(1);
48+
}
49+
}
50+
51+
main();

utils/check-breadcrumbs.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)