forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-links.js
More file actions
52 lines (45 loc) · 1.3 KB
/
validate-links.js
File metadata and controls
52 lines (45 loc) · 1.3 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
import { getTableOfContents } from "fumadocs-core/server";
import { getSlugs, parseFilePath } from "fumadocs-core/source";
import {
printErrors,
readFiles,
scanURLs,
validateFiles,
} from "next-validate-link";
import path from "node:path";
async function checkLinks() {
// we read them all at once to avoid repeated file read
const docsFiles = await readFiles("content/docs/**/*.{md,mdx}");
const exampleFiles = await readFiles("content/examples/**/*.{md,mdx}");
const scanned = await scanURLs({
populate: {
"examples/[[...slug]]": exampleFiles.map((file) => {
const info = parseFilePath(
path.relative("content/examples", 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, ...exampleFiles], {
scanned,
}),
true,
);
}
void checkLinks();