validate-mdx-links 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +31 -7
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# validate-mdx-links
|
|
2
2
|
|
|
3
|
-
Wraps `next-validate-link` with heuristics
|
|
4
|
-
|
|
3
|
+
Validates internal links in MDX files. Wraps `next-validate-link` with heuristics that cut false positives for relative paths, file extensions, and framework-specific routing.
|
|
4
|
+
|
|
5
|
+
## Supported Frameworks
|
|
6
|
+
|
|
7
|
+
- **Next.js** — App Router (`app/`) and Pages Router (`pages/`)
|
|
8
|
+
- **Fumadocs** — content-directory scanning (`content/`)
|
|
9
|
+
- **TanStack Router** — `src/routes/` with `$params`, `_layout` prefixes, `[.]` literal dots
|
|
10
|
+
|
|
11
|
+
Detection reads `package.json` dependencies first, then falls back to directory heuristics.
|
|
5
12
|
|
|
6
13
|
## Install
|
|
7
14
|
|
|
@@ -15,11 +22,22 @@ bun add -D validate-mdx-links
|
|
|
15
22
|
validate-mdx-links --files "content/**/*.mdx" --verbose
|
|
16
23
|
```
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
| Flag | Default | Description |
|
|
26
|
+
|------|---------|-------------|
|
|
27
|
+
| `--files` | — | Glob pattern for MDX files to validate |
|
|
28
|
+
| `--content-dir` | — | Content directory for URL scanning; sets `--files` to `${contentDir}/**/*.mdx` when omitted |
|
|
29
|
+
| `--cwd` | `process.cwd()` | Working directory |
|
|
30
|
+
| `--verbose` | `false` | Print every scanned route |
|
|
31
|
+
|
|
32
|
+
Exits `1` on broken links, `0` otherwise.
|
|
21
33
|
|
|
22
|
-
Relative links
|
|
34
|
+
### Relative links
|
|
35
|
+
|
|
36
|
+
The CLI resolves relative links (`./sibling`, `../other-dir/page`) against the content directory. It checks multiple path variants — with and without `.mdx`, and with `page.mdx` (App Router index) — before reporting a broken link.
|
|
37
|
+
|
|
38
|
+
### Heading fragments
|
|
39
|
+
|
|
40
|
+
Heading IDs follow GitHub Slugger conventions (duplicate tracking, non-ASCII preservation). Links like `./page#section` validate against extracted headings.
|
|
23
41
|
|
|
24
42
|
## API
|
|
25
43
|
|
|
@@ -29,8 +47,14 @@ import { validateMdxLinks, printErrors } from "validate-mdx-links";
|
|
|
29
47
|
const errors = await validateMdxLinks({
|
|
30
48
|
cwd: "/path/to/docs",
|
|
31
49
|
files: "content/**/*.mdx",
|
|
50
|
+
contentDir: "content",
|
|
32
51
|
verbose: true,
|
|
33
52
|
});
|
|
53
|
+
|
|
54
|
+
if (errors.length) {
|
|
55
|
+
printErrors(errors);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
34
58
|
```
|
|
35
59
|
|
|
36
|
-
|
|
60
|
+
`validateMdxLinks` returns `ValidationResult[]`; each entry has `file` and `detected` fields. Pass the array to `printErrors` or build a custom reporter.
|
package/dist/index.js
CHANGED
|
@@ -182,6 +182,7 @@ function buildContentScanResult(contentDir, cwd, verbose, deps) {
|
|
|
182
182
|
return { urls, fallbackUrls };
|
|
183
183
|
}
|
|
184
184
|
export async function validateMdxLinks({ cwd = process.cwd(), files: filesGlob, verbose = false, contentDir, }) {
|
|
185
|
+
cwd = resolve(cwd);
|
|
185
186
|
const originalCwd = process.cwd();
|
|
186
187
|
process.chdir(cwd);
|
|
187
188
|
const files = globSync(filesGlob);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED