starlight-links-validator 0.9.1 → 0.10.1
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/index.ts +3 -1
- package/libs/remark.ts +13 -4
- package/package.json +2 -1
package/index.ts
CHANGED
|
@@ -67,7 +67,9 @@ export default function starlightLinksValidatorPlugin(
|
|
|
67
67
|
|
|
68
68
|
updateConfig({
|
|
69
69
|
markdown: {
|
|
70
|
-
remarkPlugins: [
|
|
70
|
+
remarkPlugins: [
|
|
71
|
+
[remarkStarlightLinksValidator, { base: astroConfig.base, srcDir: astroConfig.srcDir }],
|
|
72
|
+
],
|
|
71
73
|
},
|
|
72
74
|
})
|
|
73
75
|
},
|
package/libs/remark.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import 'mdast-util-mdx-jsx'
|
|
2
2
|
|
|
3
3
|
import nodePath from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
4
5
|
|
|
5
6
|
import GitHubSlugger, { slug } from 'github-slugger'
|
|
6
7
|
import type { Nodes } from 'hast'
|
|
@@ -20,10 +21,13 @@ const headings: Headings = new Map()
|
|
|
20
21
|
// All the internal links keyed by file path.
|
|
21
22
|
const links: Links = new Map()
|
|
22
23
|
|
|
23
|
-
export const remarkStarlightLinksValidator: Plugin<[base: string], Root> = function (
|
|
24
|
+
export const remarkStarlightLinksValidator: Plugin<[{ base: string; srcDir: URL }], Root> = function ({
|
|
25
|
+
base,
|
|
26
|
+
srcDir,
|
|
27
|
+
}) {
|
|
24
28
|
return (tree, file) => {
|
|
25
29
|
const slugger = new GitHubSlugger()
|
|
26
|
-
const filePath = normalizeFilePath(base, file.history[0])
|
|
30
|
+
const filePath = normalizeFilePath(base, srcDir, file.history[0])
|
|
27
31
|
const slug = file.data.astro?.frontmatter?.slug
|
|
28
32
|
|
|
29
33
|
const fileHeadings: string[] = []
|
|
@@ -39,6 +43,11 @@ export const remarkStarlightLinksValidator: Plugin<[base: string], Root> = funct
|
|
|
39
43
|
// https://github.com/syntax-tree/mdast-util-mdx-jsx#nodes
|
|
40
44
|
switch (node.type) {
|
|
41
45
|
case 'heading': {
|
|
46
|
+
if (node.data?.hProperties?.['id']) {
|
|
47
|
+
fileHeadings.push(String(node.data.hProperties['id']))
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
const content = toString(node)
|
|
43
52
|
|
|
44
53
|
if (content.length === 0) {
|
|
@@ -142,13 +151,13 @@ function getFilePath(filePath: string, slug: string | undefined) {
|
|
|
142
151
|
return slug ? stripLeadingSlash(ensureTrailingSlash(slug)) : filePath
|
|
143
152
|
}
|
|
144
153
|
|
|
145
|
-
function normalizeFilePath(base: string, filePath?: string) {
|
|
154
|
+
function normalizeFilePath(base: string, srcDir: URL, filePath?: string) {
|
|
146
155
|
if (!filePath) {
|
|
147
156
|
throw new Error('Missing file path to validate links.')
|
|
148
157
|
}
|
|
149
158
|
|
|
150
159
|
const path = nodePath
|
|
151
|
-
.relative(nodePath.join(
|
|
160
|
+
.relative(nodePath.join(fileURLToPath(srcDir), 'content/docs'), filePath)
|
|
152
161
|
.replace(/\.\w+$/, '')
|
|
153
162
|
.replace(/index$/, '')
|
|
154
163
|
.replace(/[/\\]?$/, '/')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-links-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Starlight plugin to validate internal links.",
|
|
6
6
|
"author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@types/picomatch": "2.3.3",
|
|
28
28
|
"astro": "4.0.4",
|
|
29
29
|
"mdast-util-mdx-jsx": "3.0.0",
|
|
30
|
+
"remark-custom-heading-id": "2.0.0",
|
|
30
31
|
"typescript": "5.1.3",
|
|
31
32
|
"unified": "11.0.4",
|
|
32
33
|
"vfile": "6.0.1",
|