-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.ts
More file actions
60 lines (51 loc) · 1.67 KB
/
lint.ts
File metadata and controls
60 lines (51 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import fs from 'node:fs';
import path from 'node:path';
import { getTableOfContents } from 'fumadocs-core/server';
import { getSlugs, parseFilePath } from 'fumadocs-core/source';
import { printErrors, readFiles, scanURLs, validateFiles } from 'next-validate-link';
async function checkLinks() {
const docsFiles = await readFiles('content/docs/**/*.{md,mdx}');
const scanned = await scanURLs({
populate: {
// "(home)/blog/[slug]": blogFiles.map((file) => {
// const info = parseFilePath(path.relative("content/blog", file.path));
// return {
// value: getSlugs(info)[0],
// hashes: getTableOfContents(file.content).map((item) =>
// item.url.slice(1)
// ),
// };
// }),
'(docs)/[...slug]': docsFiles.map((file) => {
const info = parseFilePath(path.relative('content/docs', file.path));
return {
value: getSlugs(info),
hashes: getTableOfContents(file.content).map((item) => item.url.slice(1)),
};
}),
},
});
printErrors(
await validateFiles([...docsFiles], {
scanned,
whitelist: (url) => {
// Existing whitelist conditions
if (url.startsWith('#!') || url === 'tooltip') {
return true;
}
// Check if it's an llms.txt route
if (url.endsWith('/llms.txt')) {
const publicPath = path.join(process.cwd(), 'public', url);
if (fs.existsSync(publicPath)) {
return true;
}
console.warn(`Warning: llms.txt file not found at ${publicPath}`);
return false;
}
return false;
},
}),
true,
);
}
void checkLinks();