starlight-links-validator 0.7.1 → 0.8.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 +9 -0
- package/libs/validation.ts +11 -0
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -33,6 +33,15 @@ const starlightLinksValidatorOptionsSchema = z
|
|
|
33
33
|
* @default true
|
|
34
34
|
*/
|
|
35
35
|
errorOnRelativeLinks: z.boolean().default(true),
|
|
36
|
+
/**
|
|
37
|
+
* Defines a list of links 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
|
+
* The list must exactly match links as they appear in Markdown.
|
|
41
|
+
*
|
|
42
|
+
* @default []
|
|
43
|
+
*/
|
|
44
|
+
exclude: z.array(z.string()).default([]),
|
|
36
45
|
})
|
|
37
46
|
.default({})
|
|
38
47
|
|
package/libs/validation.ts
CHANGED
|
@@ -108,6 +108,10 @@ export function logErrors(pluginLogger: AstroIntegrationLogger, errors: Validati
|
|
|
108
108
|
function validateLink(context: ValidationContext) {
|
|
109
109
|
const { astroConfig, errors, filePath, link, localeConfig, options, pages } = context
|
|
110
110
|
|
|
111
|
+
if (isExcludedLink(link, context)) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
const sanitizedLink = link.replace(/^\//, '')
|
|
112
116
|
const segments = sanitizedLink.split('#')
|
|
113
117
|
|
|
@@ -211,6 +215,13 @@ function isValidAsset(path: string, context: ValidationContext) {
|
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Check if a link is explicitly excluded from validation by the user.
|
|
220
|
+
*/
|
|
221
|
+
function isExcludedLink(link: string, context: ValidationContext) {
|
|
222
|
+
return context.options.exclude.includes(link)
|
|
223
|
+
}
|
|
224
|
+
|
|
214
225
|
function addError(errors: ValidationErrors, filePath: string, link: string, type: ValidationErrorType) {
|
|
215
226
|
const fileErrors = errors.get(filePath) ?? []
|
|
216
227
|
fileErrors.push({ link, type })
|