starlight-links-validator 0.3.0 → 0.4.0
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 +5 -1
- package/libs/remark.ts +0 -1
- package/libs/validation.ts +5 -5
- package/package.json +13 -12
package/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AstroIntegration } from 'astro'
|
|
2
|
+
import { AstroError } from 'astro/errors'
|
|
2
3
|
|
|
3
4
|
import { remarkStarlightLinksValidator } from './libs/remark'
|
|
4
5
|
import { logErrors, validateLinks } from './libs/validation'
|
|
@@ -24,7 +25,10 @@ export default function starlightLinksValidatorIntegration(): AstroIntegration {
|
|
|
24
25
|
logErrors(errors)
|
|
25
26
|
|
|
26
27
|
if (errors.size > 0) {
|
|
27
|
-
throw new
|
|
28
|
+
throw new AstroError(
|
|
29
|
+
'Links validation failed.',
|
|
30
|
+
`See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-links-validator/issues/new/choose.`,
|
|
31
|
+
)
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
},
|
package/libs/remark.ts
CHANGED
|
@@ -85,7 +85,6 @@ export const remarkStarlightLinksValidator: Plugin<[], Root> = function () {
|
|
|
85
85
|
case 'html': {
|
|
86
86
|
const htmlTree = fromHtml(node.value, { fragment: true })
|
|
87
87
|
|
|
88
|
-
// @ts-expect-error - https://github.com/microsoft/TypeScript/issues/51188
|
|
89
88
|
visit(htmlTree, (htmlNode: Nodes) => {
|
|
90
89
|
if (hasProperty(htmlNode, 'id') && typeof htmlNode.properties.id === 'string') {
|
|
91
90
|
fileHeadings.push(htmlNode.properties.id)
|
package/libs/validation.ts
CHANGED
|
@@ -39,10 +39,10 @@ export function logErrors(errors: ValidationErrors) {
|
|
|
39
39
|
red(
|
|
40
40
|
`Found ${errorCount} invalid ${pluralize(errorCount, 'link')} in ${errors.size} ${pluralize(
|
|
41
41
|
errors.size,
|
|
42
|
-
'file'
|
|
43
|
-
)}
|
|
44
|
-
)
|
|
45
|
-
)}\n\n
|
|
42
|
+
'file',
|
|
43
|
+
)}.`,
|
|
44
|
+
),
|
|
45
|
+
)}\n\n`,
|
|
46
46
|
)
|
|
47
47
|
|
|
48
48
|
for (const [file, links] of errors) {
|
|
@@ -67,7 +67,7 @@ function validateLink(
|
|
|
67
67
|
filePath: string,
|
|
68
68
|
headings: Headings,
|
|
69
69
|
pages: Pages,
|
|
70
|
-
outputDir: URL
|
|
70
|
+
outputDir: URL,
|
|
71
71
|
) {
|
|
72
72
|
const sanitizedLink = link.replace(/^\//, '')
|
|
73
73
|
const segments = sanitizedLink.split('#')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-links-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Astro integration for Starlight to validate internal links.",
|
|
6
6
|
"author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
|
|
@@ -14,25 +14,26 @@
|
|
|
14
14
|
"hast-util-from-html": "2.0.1",
|
|
15
15
|
"hast-util-has-property": "3.0.0",
|
|
16
16
|
"kleur": "4.1.5",
|
|
17
|
-
"mdast-util-to-string": "
|
|
18
|
-
"unist-util-visit": "
|
|
17
|
+
"mdast-util-to-string": "4.0.0",
|
|
18
|
+
"unist-util-visit": "5.0.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@types/
|
|
23
|
-
"@types/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
21
|
+
"@astrojs/starlight": "0.10.1",
|
|
22
|
+
"@types/hast": "3.0.1",
|
|
23
|
+
"@types/mdast": "4.0.0",
|
|
24
|
+
"@types/node": "18.17.18",
|
|
25
|
+
"astro": "3.1.1",
|
|
26
|
+
"mdast-util-mdx-jsx": "3.0.0",
|
|
26
27
|
"typescript": "5.1.3",
|
|
27
|
-
"unified": "
|
|
28
|
+
"unified": "11.0.3",
|
|
28
29
|
"vitest": "0.32.2"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"@astrojs/starlight": ">=0.0
|
|
32
|
-
"astro": ">=
|
|
32
|
+
"@astrojs/starlight": ">=0.9.0",
|
|
33
|
+
"astro": ">=3.0.0"
|
|
33
34
|
},
|
|
34
35
|
"engines": {
|
|
35
|
-
"node": ">=18"
|
|
36
|
+
"node": ">=18.14.1"
|
|
36
37
|
},
|
|
37
38
|
"packageManager": "pnpm@8.6.3",
|
|
38
39
|
"publishConfig": {
|