-
-
Notifications
You must be signed in to change notification settings - Fork 764
Expand file tree
/
Copy pathvalidate-links.mjs
More file actions
50 lines (49 loc) · 1.47 KB
/
Copy pathvalidate-links.mjs
File metadata and controls
50 lines (49 loc) · 1.47 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
import { getTableOfContents } from "fumadocs-core/content/toc";
import { getSlugs } from "fumadocs-core/source";
import {
printErrors,
readFiles,
scanURLs,
validateFiles,
} from "next-validate-link";
import path from "node:path";
async function checkLinks() {
const docsFiles = await readFiles("content/docs/**/*.{md,mdx}");
const pagesFiles = await readFiles("content/pages/**/*.{md,mdx}");
const examplesFiles = await readFiles("content/examples/**/*.{md,mdx}");
const scanned = await scanURLs({
populate: {
"[...slug]": pagesFiles.map((file) => {
return {
value: getSlugs(path.relative("content/pages", file.path)),
hashes: getTableOfContents(file.content).map((item) =>
item.url.slice(1),
),
};
}),
"docs/[[...slug]]": docsFiles.map((file) => {
return {
value: getSlugs(path.relative("content/docs", file.path)),
hashes: getTableOfContents(file.content).map((item) =>
item.url.slice(1),
),
};
}),
"examples/[[...slug]]": examplesFiles.map((file) => {
return {
value: getSlugs(path.relative("content/examples", file.path)),
hashes: getTableOfContents(file.content).map((item) =>
item.url.slice(1),
),
};
}),
},
});
printErrors(
await validateFiles([...docsFiles, ...pagesFiles, ...examplesFiles], {
scanned,
}),
true,
);
}
void checkLinks();