starlight-links-validator 0.13.2 → 0.13.4
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/libs/remark.ts +3 -1
- package/libs/validation.ts +10 -8
- package/package.json +1 -1
package/libs/remark.ts
CHANGED
|
@@ -56,7 +56,9 @@ export const remarkStarlightLinksValidator: Plugin<[{ base: string; srcDir: URL
|
|
|
56
56
|
break
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
// Remove the last trailing hyphen from the slug like Astro does if it exists.
|
|
60
|
+
// https://github.com/withastro/astro/blob/74ee2e45ecc9edbe285eadee6d0b94fc47d0d125/packages/integrations/markdoc/src/heading-ids.ts#L21
|
|
61
|
+
fileHeadings.push(slugger.slug(content).replace(/-$/, ''))
|
|
60
62
|
|
|
61
63
|
break
|
|
62
64
|
}
|
package/libs/validation.ts
CHANGED
|
@@ -19,7 +19,8 @@ export const ValidationErrorType = {
|
|
|
19
19
|
InvalidLink: 'invalid link',
|
|
20
20
|
LocalLink: 'local link',
|
|
21
21
|
RelativeLink: 'relative link',
|
|
22
|
-
|
|
22
|
+
TrailingSlashMissing: 'missing trailing slash',
|
|
23
|
+
TrailingSlashForbidden: 'forbidden trailing slash',
|
|
23
24
|
} as const
|
|
24
25
|
|
|
25
26
|
export function validateLinks(
|
|
@@ -168,13 +169,14 @@ function validateLink(context: ValidationContext) {
|
|
|
168
169
|
return
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
if (path.length > 0) {
|
|
173
|
+
if (astroConfig.trailingSlash === 'always' && !path.endsWith('/')) {
|
|
174
|
+
addError(errors, filePath, link, ValidationErrorType.TrailingSlashMissing)
|
|
175
|
+
return
|
|
176
|
+
} else if (astroConfig.trailingSlash === 'never' && path.endsWith('/')) {
|
|
177
|
+
addError(errors, filePath, link, ValidationErrorType.TrailingSlashForbidden)
|
|
178
|
+
return
|
|
179
|
+
}
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
182
|
|