starlight-links-validator 0.10.0 → 0.10.1
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 +3 -1
- package/libs/remark.ts +8 -4
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -67,7 +67,9 @@ export default function starlightLinksValidatorPlugin(
|
|
|
67
67
|
|
|
68
68
|
updateConfig({
|
|
69
69
|
markdown: {
|
|
70
|
-
remarkPlugins: [
|
|
70
|
+
remarkPlugins: [
|
|
71
|
+
[remarkStarlightLinksValidator, { base: astroConfig.base, srcDir: astroConfig.srcDir }],
|
|
72
|
+
],
|
|
71
73
|
},
|
|
72
74
|
})
|
|
73
75
|
},
|
package/libs/remark.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import 'mdast-util-mdx-jsx'
|
|
2
2
|
|
|
3
3
|
import nodePath from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
4
5
|
|
|
5
6
|
import GitHubSlugger, { slug } from 'github-slugger'
|
|
6
7
|
import type { Nodes } from 'hast'
|
|
@@ -20,10 +21,13 @@ const headings: Headings = new Map()
|
|
|
20
21
|
// All the internal links keyed by file path.
|
|
21
22
|
const links: Links = new Map()
|
|
22
23
|
|
|
23
|
-
export const remarkStarlightLinksValidator: Plugin<[base: string], Root> = function (
|
|
24
|
+
export const remarkStarlightLinksValidator: Plugin<[{ base: string; srcDir: URL }], Root> = function ({
|
|
25
|
+
base,
|
|
26
|
+
srcDir,
|
|
27
|
+
}) {
|
|
24
28
|
return (tree, file) => {
|
|
25
29
|
const slugger = new GitHubSlugger()
|
|
26
|
-
const filePath = normalizeFilePath(base, file.history[0])
|
|
30
|
+
const filePath = normalizeFilePath(base, srcDir, file.history[0])
|
|
27
31
|
const slug = file.data.astro?.frontmatter?.slug
|
|
28
32
|
|
|
29
33
|
const fileHeadings: string[] = []
|
|
@@ -147,13 +151,13 @@ function getFilePath(filePath: string, slug: string | undefined) {
|
|
|
147
151
|
return slug ? stripLeadingSlash(ensureTrailingSlash(slug)) : filePath
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
function normalizeFilePath(base: string, filePath?: string) {
|
|
154
|
+
function normalizeFilePath(base: string, srcDir: URL, filePath?: string) {
|
|
151
155
|
if (!filePath) {
|
|
152
156
|
throw new Error('Missing file path to validate links.')
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
const path = nodePath
|
|
156
|
-
.relative(nodePath.join(
|
|
160
|
+
.relative(nodePath.join(fileURLToPath(srcDir), 'content/docs'), filePath)
|
|
157
161
|
.replace(/\.\w+$/, '')
|
|
158
162
|
.replace(/index$/, '')
|
|
159
163
|
.replace(/[/\\]?$/, '/')
|