starlight-links-validator 0.5.3 → 0.6.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/libs/remark.ts +18 -3
- package/libs/validation.ts +3 -1
- package/package.json +2 -1
package/libs/remark.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { toString } from 'mdast-util-to-string'
|
|
|
13
13
|
import type { Plugin } from 'unified'
|
|
14
14
|
import { visit } from 'unist-util-visit'
|
|
15
15
|
|
|
16
|
-
import { stripLeadingSlash } from './path'
|
|
16
|
+
import { ensureTrailingSlash, stripLeadingSlash } from './path'
|
|
17
17
|
|
|
18
18
|
// All the headings keyed by file path.
|
|
19
19
|
const headings: Headings = new Map()
|
|
@@ -24,6 +24,7 @@ export const remarkStarlightLinksValidator: Plugin<[base: string], Root> = funct
|
|
|
24
24
|
return (tree, file) => {
|
|
25
25
|
const slugger = new GitHubSlugger()
|
|
26
26
|
const filePath = normalizeFilePath(base, file.history[0])
|
|
27
|
+
const slug = file.data.astro?.frontmatter?.slug
|
|
27
28
|
|
|
28
29
|
const fileHeadings: string[] = []
|
|
29
30
|
const fileLinks: string[] = []
|
|
@@ -124,8 +125,8 @@ export const remarkStarlightLinksValidator: Plugin<[base: string], Root> = funct
|
|
|
124
125
|
}
|
|
125
126
|
})
|
|
126
127
|
|
|
127
|
-
headings.set(filePath, fileHeadings)
|
|
128
|
-
links.set(filePath, fileLinks)
|
|
128
|
+
headings.set(getFilePath(filePath, slug), fileHeadings)
|
|
129
|
+
links.set(getFilePath(filePath, slug), fileLinks)
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -137,6 +138,10 @@ function isInternalLink(link: string) {
|
|
|
137
138
|
return !isAbsoluteUrl(link)
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
function getFilePath(filePath: string, slug: string | undefined) {
|
|
142
|
+
return slug ? stripLeadingSlash(ensureTrailingSlash(slug)) : filePath
|
|
143
|
+
}
|
|
144
|
+
|
|
140
145
|
function normalizeFilePath(base: string, filePath?: string) {
|
|
141
146
|
if (!filePath) {
|
|
142
147
|
throw new Error('Missing file path to validate links.')
|
|
@@ -170,3 +175,13 @@ interface MdxIdAttribute {
|
|
|
170
175
|
type: 'mdxJsxAttribute'
|
|
171
176
|
value: string
|
|
172
177
|
}
|
|
178
|
+
|
|
179
|
+
declare module 'vfile' {
|
|
180
|
+
interface DataMap {
|
|
181
|
+
astro?: {
|
|
182
|
+
frontmatter?: {
|
|
183
|
+
slug?: string
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
package/libs/validation.ts
CHANGED
|
@@ -32,7 +32,9 @@ export function validateLinks(
|
|
|
32
32
|
const { headings, links } = getValidationData()
|
|
33
33
|
const allPages: Pages = new Set(
|
|
34
34
|
pages.map((page) =>
|
|
35
|
-
ensureTrailingSlash(
|
|
35
|
+
ensureTrailingSlash(
|
|
36
|
+
base === '/' ? stripLeadingSlash(page.pathname) : posix.join(stripLeadingSlash(base), page.pathname),
|
|
37
|
+
),
|
|
36
38
|
),
|
|
37
39
|
)
|
|
38
40
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-links-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Starlight plugin to validate internal links.",
|
|
6
6
|
"author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"mdast-util-mdx-jsx": "3.0.0",
|
|
28
28
|
"typescript": "5.1.3",
|
|
29
29
|
"unified": "11.0.4",
|
|
30
|
+
"vfile": "6.0.1",
|
|
30
31
|
"vitest": "1.0.4"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|