starlight-links-validator 0.7.0 → 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 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
 
@@ -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
 
@@ -151,8 +155,9 @@ function validateLink(context: ValidationContext) {
151
155
  }
152
156
 
153
157
  if (
154
- (astroConfig.trailingSlash === 'always' && !path.endsWith('/')) ||
155
- (astroConfig.trailingSlash === 'never' && path.endsWith('/'))
158
+ path.length > 0 &&
159
+ ((astroConfig.trailingSlash === 'always' && !path.endsWith('/')) ||
160
+ (astroConfig.trailingSlash === 'never' && path.endsWith('/')))
156
161
  ) {
157
162
  addError(errors, filePath, link, ValidationErrorType.TrailingSlash)
158
163
  return
@@ -210,6 +215,13 @@ function isValidAsset(path: string, context: ValidationContext) {
210
215
  }
211
216
  }
212
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
+
213
225
  function addError(errors: ValidationErrors, filePath: string, link: string, type: ValidationErrorType) {
214
226
  const fileErrors = errors.get(filePath) ?? []
215
227
  fileErrors.push({ link, type })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-links-validator",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to validate internal links.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",