starlight-links-validator 0.18.0 → 0.19.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # starlight-links-validator
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#123](https://github.com/HiDeoo/starlight-links-validator/pull/123) [`e9cc59d`](https://github.com/HiDeoo/starlight-links-validator/commit/e9cc59de376c7602f70e9310e320fdd6d44a17d3) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds validation of [hero action links](https://starlight.astro.build/reference/frontmatter/#hero) in frontmatter.
8
+
9
+ - [#123](https://github.com/HiDeoo/starlight-links-validator/pull/123) [`e9cc59d`](https://github.com/HiDeoo/starlight-links-validator/commit/e9cc59de376c7602f70e9310e320fdd6d44a17d3) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds validation of [previous](https://starlight.astro.build/reference/frontmatter/#prev) and [next](https://starlight.astro.build/reference/frontmatter/#next) page links in frontmatter.
10
+
11
+ ## 0.18.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#121](https://github.com/HiDeoo/starlight-links-validator/pull/121) [`242bc28`](https://github.com/HiDeoo/starlight-links-validator/commit/242bc2862aa7d911d5de0301e5caa29342e92ffd) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Setups trusted publishing using OpenID Connect (OIDC) authentication — no code changes.
16
+
3
17
  ## 0.18.0
4
18
 
5
19
  ### Minor Changes
package/libs/remark.ts CHANGED
@@ -14,6 +14,7 @@ import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from 'mdast-util-mdx-
14
14
  import { toString } from 'mdast-util-to-string'
15
15
  import type { Plugin } from 'unified'
16
16
  import { visit } from 'unist-util-visit'
17
+ import type { DataMap } from 'vfile'
17
18
 
18
19
  import type { StarlightLinksValidatorOptions } from '..'
19
20
 
@@ -53,6 +54,8 @@ export const remarkStarlightLinksValidator: Plugin<[RemarkStarlightLinksValidato
53
54
  const fileLinks: Link[] = []
54
55
  const fileDefinitions = new Map<string, string>()
55
56
 
57
+ extractFrontmatterLinks(file.data.astro?.frontmatter, fileLinks, config)
58
+
56
59
  visit(tree, 'definition', (node) => {
57
60
  fileDefinitions.set(node.identifier, node.url)
58
61
  })
@@ -230,6 +233,54 @@ function isMdxIdAttribute(attribute: MdxJsxAttribute | MdxJsxExpressionAttribute
230
233
  return attribute.type === 'mdxJsxAttribute' && attribute.name === 'id' && typeof attribute.value === 'string'
231
234
  }
232
235
 
236
+ function extractFrontmatterLinks(
237
+ frontmatter: Frontmatter,
238
+ fileLinks: Link[],
239
+ config: RemarkStarlightLinksValidatorConfig,
240
+ ) {
241
+ if (!frontmatter) return
242
+
243
+ if (isFrontmatterWithHeroActions(frontmatter)) {
244
+ for (const action of frontmatter.hero.actions) {
245
+ const link = getLinkToValidate(action.link, config)
246
+ if (link) fileLinks.push(link)
247
+ }
248
+ }
249
+
250
+ if (isFrontmatterPrevNextLink(frontmatter, 'prev')) {
251
+ const link = getLinkToValidate(frontmatter.prev.link, config)
252
+ if (link) fileLinks.push(link)
253
+ }
254
+
255
+ if (isFrontmatterPrevNextLink(frontmatter, 'next')) {
256
+ const link = getLinkToValidate(frontmatter.next.link, config)
257
+ if (link) fileLinks.push(link)
258
+ }
259
+ }
260
+
261
+ function isFrontmatterWithHeroActions(
262
+ frontmatter: Frontmatter,
263
+ ): frontmatter is Frontmatter & { hero: FrontmatterHeroActions } {
264
+ return (
265
+ frontmatter !== undefined &&
266
+ 'hero' in frontmatter &&
267
+ typeof frontmatter['hero'] === 'object' &&
268
+ 'actions' in frontmatter['hero']
269
+ )
270
+ }
271
+
272
+ function isFrontmatterPrevNextLink<T extends 'prev' | 'next'>(
273
+ frontmatter: Frontmatter,
274
+ type: T,
275
+ ): frontmatter is Frontmatter & Record<T, FrontmatterPrevNextLink> {
276
+ return (
277
+ frontmatter !== undefined &&
278
+ type in frontmatter &&
279
+ typeof frontmatter[type] === 'object' &&
280
+ 'link' in frontmatter[type]
281
+ )
282
+ }
283
+
233
284
  export interface RemarkStarlightLinksValidatorConfig {
234
285
  base: string
235
286
  options: StarlightLinksValidatorOptions
@@ -260,3 +311,13 @@ interface MdxIdAttribute {
260
311
  type: 'mdxJsxAttribute'
261
312
  value: string
262
313
  }
314
+
315
+ type Frontmatter = DataMap['astro']['frontmatter']
316
+
317
+ interface FrontmatterHeroActions {
318
+ actions: { link: string }[]
319
+ }
320
+
321
+ interface FrontmatterPrevNextLink {
322
+ link: string
323
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-links-validator",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "license": "MIT",
5
5
  "description": "Starlight plugin to validate internal links.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
@@ -41,8 +41,7 @@
41
41
  },
42
42
  "packageManager": "pnpm@8.6.3",
43
43
  "publishConfig": {
44
- "access": "public",
45
- "provenance": true
44
+ "access": "public"
46
45
  },
47
46
  "sideEffects": false,
48
47
  "keywords": [