starlight-links-validator 0.13.4 → 0.14.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/CHANGELOG.md +15 -0
- package/index.ts +4 -1
- package/libs/astro.ts +17 -0
- package/libs/remark.ts +3 -13
- package/package.json +25 -27
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# starlight-links-validator
|
|
2
|
+
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#77](https://github.com/HiDeoo/starlight-links-validator/pull/77) [`486a379`](https://github.com/HiDeoo/starlight-links-validator/commit/486a379c5bda40584126c376e14a3c82c23bd449) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for Astro v5, drops support for Astro v4.
|
|
8
|
+
|
|
9
|
+
⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.30.0`.
|
|
10
|
+
|
|
11
|
+
Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs/starlight%400.30.0) to update your project.
|
|
12
|
+
|
|
13
|
+
When using the plugin with the [Content Layer API](https://docs.astro.build/en/guides/content-collections), the plugin will now automatically invalidate the content layer cache so that all links can be properly validated. To avoid unnecessary cache invalidation, it is recommended to conditionally use the plugin only when necessary. Check out the new [“Conditional Validation”](https://starlight-links-validator.vercel.app/guides/conditional-validation/) guide for more information.
|
|
14
|
+
|
|
15
|
+
⚠️ **BREAKING CHANGE:** Due to a [regression](https://github.com/withastro/astro/issues/12778) in Astro v5, links to pages with [custom IDs/slugs](https://docs.astro.build/en/guides/content-collections/#defining-custom-ids) can no longer be validated and will be flagged as invalid. If you rely on this feature, please stay on a previous version of Starlight and Astro in the meantime.
|
package/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { StarlightPlugin } from '@astrojs/starlight/types'
|
|
|
2
2
|
import { AstroError } from 'astro/errors'
|
|
3
3
|
import { z } from 'astro/zod'
|
|
4
4
|
|
|
5
|
+
import { clearContentLayerCache } from './libs/astro'
|
|
5
6
|
import { remarkStarlightLinksValidator } from './libs/remark'
|
|
6
7
|
import { logErrors, validateLinks } from './libs/validation'
|
|
7
8
|
|
|
@@ -74,11 +75,13 @@ export default function starlightLinksValidatorPlugin(
|
|
|
74
75
|
addIntegration({
|
|
75
76
|
name: 'starlight-links-validator-integration',
|
|
76
77
|
hooks: {
|
|
77
|
-
'astro:config:setup': ({ command, updateConfig }) => {
|
|
78
|
+
'astro:config:setup': async ({ command, updateConfig }) => {
|
|
78
79
|
if (command !== 'build') {
|
|
79
80
|
return
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
await clearContentLayerCache(astroConfig, logger)
|
|
84
|
+
|
|
82
85
|
updateConfig({
|
|
83
86
|
markdown: {
|
|
84
87
|
remarkPlugins: [
|
package/libs/astro.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import type { AstroConfig, AstroIntegrationLogger } from 'astro'
|
|
4
|
+
|
|
5
|
+
const dataStoreFile = 'data-store.json'
|
|
6
|
+
|
|
7
|
+
export async function clearContentLayerCache(config: AstroConfig, logger: AstroIntegrationLogger) {
|
|
8
|
+
const dataStore = getDataStoreFile(config)
|
|
9
|
+
if (fs.existsSync(dataStore)) {
|
|
10
|
+
logger.info('Invalidating content layer cache…')
|
|
11
|
+
await fs.promises.rm(dataStore, { force: true })
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getDataStoreFile(config: AstroConfig) {
|
|
16
|
+
return new URL(dataStoreFile, config.cacheDir)
|
|
17
|
+
}
|
package/libs/remark.ts
CHANGED
|
@@ -26,11 +26,12 @@ export const remarkStarlightLinksValidator: Plugin<[{ base: string; srcDir: URL
|
|
|
26
26
|
srcDir,
|
|
27
27
|
}) {
|
|
28
28
|
return (tree, file) => {
|
|
29
|
-
if (file.data.astro?.frontmatter?.draft) return
|
|
29
|
+
if (file.data.astro?.frontmatter?.['draft']) return
|
|
30
30
|
|
|
31
31
|
const slugger = new GitHubSlugger()
|
|
32
32
|
const filePath = normalizeFilePath(base, srcDir, file.history[0])
|
|
33
|
-
const slug =
|
|
33
|
+
const slug: string | undefined =
|
|
34
|
+
typeof file.data.astro?.frontmatter?.['slug'] === 'string' ? file.data.astro.frontmatter['slug'] : undefined
|
|
34
35
|
|
|
35
36
|
const fileHeadings: string[] = []
|
|
36
37
|
const fileLinks: string[] = []
|
|
@@ -202,14 +203,3 @@ interface MdxIdAttribute {
|
|
|
202
203
|
type: 'mdxJsxAttribute'
|
|
203
204
|
value: string
|
|
204
205
|
}
|
|
205
|
-
|
|
206
|
-
declare module 'vfile' {
|
|
207
|
-
interface DataMap {
|
|
208
|
-
astro?: {
|
|
209
|
-
frontmatter?: {
|
|
210
|
-
draft?: boolean
|
|
211
|
-
slug?: string
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-links-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Starlight plugin to validate internal links.",
|
|
6
6
|
"author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
|
|
@@ -10,39 +10,36 @@
|
|
|
10
10
|
"./package.json": "./package.json"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@types/picomatch": "
|
|
14
|
-
"github-slugger": "2.0.0",
|
|
15
|
-
"hast-util-from-html": "2.0.
|
|
16
|
-
"hast-util-has-property": "3.0.0",
|
|
17
|
-
"is-absolute-url": "4.0.1",
|
|
18
|
-
"kleur": "4.1.5",
|
|
19
|
-
"mdast-util-to-string": "4.0.0",
|
|
20
|
-
"picomatch": "4.0.2",
|
|
21
|
-
"unist-util-visit": "5.0.0"
|
|
13
|
+
"@types/picomatch": "^3.0.1",
|
|
14
|
+
"github-slugger": "^2.0.0",
|
|
15
|
+
"hast-util-from-html": "^2.0.3",
|
|
16
|
+
"hast-util-has-property": "^3.0.0",
|
|
17
|
+
"is-absolute-url": "^4.0.1",
|
|
18
|
+
"kleur": "^4.1.5",
|
|
19
|
+
"mdast-util-to-string": "^4.0.0",
|
|
20
|
+
"picomatch": "^4.0.2",
|
|
21
|
+
"unist-util-visit": "^5.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@types/
|
|
26
|
-
"@types/
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"unified": "11.0.4",
|
|
33
|
-
"vfile": "6.0.1",
|
|
34
|
-
"vitest": "1.0.4"
|
|
24
|
+
"@types/hast": "^3.0.4",
|
|
25
|
+
"@types/mdast": "^4.0.4",
|
|
26
|
+
"@types/node": "^18.19.68",
|
|
27
|
+
"mdast-util-mdx-jsx": "^3.1.3",
|
|
28
|
+
"remark-custom-heading-id": "^2.0.0",
|
|
29
|
+
"unified": "^11.0.5",
|
|
30
|
+
"vfile": "^6.0.3",
|
|
31
|
+
"vitest": "2.1.6"
|
|
35
32
|
},
|
|
36
33
|
"peerDependencies": {
|
|
37
|
-
"@astrojs/starlight": ">=0.15.0"
|
|
38
|
-
"astro": ">=4.0.0"
|
|
34
|
+
"@astrojs/starlight": ">=0.15.0"
|
|
39
35
|
},
|
|
40
36
|
"engines": {
|
|
41
|
-
"node": ">=18.
|
|
37
|
+
"node": ">=18.17.1"
|
|
42
38
|
},
|
|
43
39
|
"packageManager": "pnpm@8.6.3",
|
|
44
40
|
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
46
43
|
},
|
|
47
44
|
"sideEffects": false,
|
|
48
45
|
"keywords": [
|
|
@@ -55,11 +52,12 @@
|
|
|
55
52
|
"homepage": "https://github.com/HiDeoo/starlight-links-validator",
|
|
56
53
|
"repository": {
|
|
57
54
|
"type": "git",
|
|
58
|
-
"url": "https://github.com/HiDeoo/starlight-links-validator.git"
|
|
55
|
+
"url": "https://github.com/HiDeoo/starlight-links-validator.git",
|
|
56
|
+
"directory": "packages/starlight-links-validator"
|
|
59
57
|
},
|
|
60
58
|
"bugs": "https://github.com/HiDeoo/starlight-links-validator/issues",
|
|
61
59
|
"scripts": {
|
|
62
60
|
"test": "vitest",
|
|
63
|
-
"lint": "
|
|
61
|
+
"lint": "eslint . --cache --max-warnings=0"
|
|
64
62
|
}
|
|
65
63
|
}
|