@astrojs/starlight 0.26.2 → 0.26.3

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,13 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.26.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2281](https://github.com/withastro/starlight/pull/2281) [`5062d30`](https://github.com/withastro/starlight/commit/5062d30c08f6ede9e6c39174537bb61280e7c23d) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a potential text rendering issue that could include extra whitespaces for text containing colons.
8
+
9
+ - [#2279](https://github.com/withastro/starlight/pull/2279) [`62d59e2`](https://github.com/withastro/starlight/commit/62d59e29d2621d834c28c764a02c58b1e1b49243) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue with frontmatter schemas containing collection references used with the `<StarlightPage />` component and an Astro version greater than `4.14.0`.
10
+
3
11
  ## 0.26.2
4
12
 
5
13
  ### Patch Changes
@@ -64,10 +64,20 @@ function transformUnhandledDirective(
64
64
  index: number,
65
65
  parent: Parent
66
66
  ) {
67
- const textNode = {
68
- type: 'text',
69
- value: toMarkdown(node, { extensions: [directiveToMarkdown()] }),
70
- } as const;
67
+ let markdown = toMarkdown(node, { extensions: [directiveToMarkdown()] });
68
+ /**
69
+ * `mdast-util-to-markdown` assumes that the tree represents a complete document (as it's an AST
70
+ * and not a CST) and to follow the POSIX definition of a line (a sequence of zero or more
71
+ * non- <newline> characters plus a terminating <newline> character), a newline is automatically
72
+ * added at the end of the output so that the output is a valid file.
73
+ * In this specific case, we can safely remove the newline character at the end of the output
74
+ * before replacing the directive with its value.
75
+ *
76
+ * @see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
77
+ * @see https://github.com/syntax-tree/mdast-util-to-markdown/blob/fd6a508cc619b862f75b762dcf876c6b8315d330/lib/index.js#L79-L85
78
+ */
79
+ if (markdown.at(-1) === '\n') markdown = markdown.slice(0, -1);
80
+ const textNode = { type: 'text', value: markdown } as const;
71
81
  if (node.type === 'textDirective') {
72
82
  parent.children[index] = textNode;
73
83
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.26.2",
3
+ "version": "0.26.3",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -25,11 +25,31 @@ export function parseWithFriendlyErrors<T extends z.Schema>(
25
25
  input: z.input<T>,
26
26
  message: string
27
27
  ): z.output<T> {
28
- const parsedConfig = schema.safeParse(input, { errorMap });
29
- if (!parsedConfig.success) {
30
- throw new AstroError(message, parsedConfig.error.issues.map((i) => i.message).join('\n'));
28
+ return processParsedData(schema.safeParse(input, { errorMap }), message);
29
+ }
30
+
31
+ /**
32
+ * Asynchronously parse data with a Zod schema that contains asynchronous refinements or transforms
33
+ * and throw a nicely formatted error if it is invalid.
34
+ *
35
+ * @param schema The Zod schema to use to parse the input.
36
+ * @param input Input data that should match the schema.
37
+ * @param message Error message preamble to use if the input fails to parse.
38
+ * @returns Validated data parsed by Zod.
39
+ */
40
+ export async function parseAsyncWithFriendlyErrors<T extends z.Schema>(
41
+ schema: T,
42
+ input: z.input<T>,
43
+ message: string
44
+ ): Promise<z.output<T>> {
45
+ return processParsedData(await schema.safeParseAsync(input, { errorMap }), message);
46
+ }
47
+
48
+ function processParsedData(parsedData: z.SafeParseReturnType<any, any>, message: string) {
49
+ if (!parsedData.success) {
50
+ throw new AstroError(message, parsedData.error.issues.map((i) => i.message).join('\n'));
31
51
  }
32
- return parsedConfig.data;
52
+ return parsedData.data;
33
53
  }
34
54
 
35
55
  const errorMap: z.ZodErrorMap = (baseError, ctx) => {
@@ -1,7 +1,7 @@
1
1
  import { z } from 'astro/zod';
2
2
  import { type ContentConfig, type SchemaContext } from 'astro:content';
3
3
  import config from 'virtual:starlight/user-config';
4
- import { parseWithFriendlyErrors } from './error-map';
4
+ import { parseWithFriendlyErrors, parseAsyncWithFriendlyErrors } from './error-map';
5
5
  import { stripLeadingAndTrailingSlashes } from './path';
6
6
  import {
7
7
  getSiteTitle,
@@ -198,7 +198,9 @@ async function getStarlightPageFrontmatter(frontmatter: StarlightPageFrontmatter
198
198
  }),
199
199
  });
200
200
 
201
- return parseWithFriendlyErrors(
201
+ // Starting with Astro 4.14.0, a frontmatter schema that contains collection references will
202
+ // contain an async transform.
203
+ return parseAsyncWithFriendlyErrors(
202
204
  schema,
203
205
  frontmatter,
204
206
  'Invalid frontmatter props passed to the `<StarlightPage/>` component.'