starlight-links-validator 0.7.1 → 0.9.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 +8 -0
- package/libs/validation.ts +12 -0
- package/package.json +3 -1
package/index.ts
CHANGED
|
@@ -33,6 +33,14 @@ const starlightLinksValidatorOptionsSchema = z
|
|
|
33
33
|
* @default true
|
|
34
34
|
*/
|
|
35
35
|
errorOnRelativeLinks: z.boolean().default(true),
|
|
36
|
+
/**
|
|
37
|
+
* Defines a list of links or glob patterns that should be excluded from validation.
|
|
38
|
+
*
|
|
39
|
+
* The links in this list will be ignored by the plugin and will not be validated.
|
|
40
|
+
*
|
|
41
|
+
* @default []
|
|
42
|
+
*/
|
|
43
|
+
exclude: z.array(z.string()).default([]),
|
|
36
44
|
})
|
|
37
45
|
.default({})
|
|
38
46
|
|
package/libs/validation.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
5
5
|
import type { StarlightPlugin } from '@astrojs/starlight/types'
|
|
6
6
|
import type { AstroConfig, AstroIntegrationLogger } from 'astro'
|
|
7
7
|
import { bgGreen, black, blue, dim, green, red } from 'kleur/colors'
|
|
8
|
+
import picomatch from 'picomatch'
|
|
8
9
|
|
|
9
10
|
import type { StarlightLinksValidatorOptions } from '..'
|
|
10
11
|
|
|
@@ -108,6 +109,10 @@ export function logErrors(pluginLogger: AstroIntegrationLogger, errors: Validati
|
|
|
108
109
|
function validateLink(context: ValidationContext) {
|
|
109
110
|
const { astroConfig, errors, filePath, link, localeConfig, options, pages } = context
|
|
110
111
|
|
|
112
|
+
if (isExcludedLink(link, context)) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
111
116
|
const sanitizedLink = link.replace(/^\//, '')
|
|
112
117
|
const segments = sanitizedLink.split('#')
|
|
113
118
|
|
|
@@ -211,6 +216,13 @@ function isValidAsset(path: string, context: ValidationContext) {
|
|
|
211
216
|
}
|
|
212
217
|
}
|
|
213
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Check if a link is excluded from validation by the user.
|
|
221
|
+
*/
|
|
222
|
+
function isExcludedLink(link: string, context: ValidationContext) {
|
|
223
|
+
return picomatch(context.options.exclude)(link)
|
|
224
|
+
}
|
|
225
|
+
|
|
214
226
|
function addError(errors: ValidationErrors, filePath: string, link: string, type: ValidationErrorType) {
|
|
215
227
|
const fileErrors = errors.get(filePath) ?? []
|
|
216
228
|
fileErrors.push({ link, type })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-links-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Starlight plugin to validate internal links.",
|
|
6
6
|
"author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"is-absolute-url": "4.0.1",
|
|
17
17
|
"kleur": "4.1.5",
|
|
18
18
|
"mdast-util-to-string": "4.0.0",
|
|
19
|
+
"picomatch": "4.0.2",
|
|
19
20
|
"unist-util-visit": "5.0.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
"@types/hast": "3.0.3",
|
|
24
25
|
"@types/mdast": "4.0.3",
|
|
25
26
|
"@types/node": "18.17.18",
|
|
27
|
+
"@types/picomatch": "2.3.3",
|
|
26
28
|
"astro": "4.0.4",
|
|
27
29
|
"mdast-util-mdx-jsx": "3.0.0",
|
|
28
30
|
"typescript": "5.1.3",
|