@astrojs/starlight 0.26.2 → 0.26.4
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 +16 -0
- package/integrations/asides.ts +14 -4
- package/package.json +1 -1
- package/utils/error-map.ts +26 -5
- package/utils/starlight-page.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.26.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2288](https://github.com/withastro/starlight/pull/2288) [`b15f725`](https://github.com/withastro/starlight/commit/b15f725ead981387f80f089d0523d9c2748b184e) Thanks [@matthewp](https://github.com/matthewp)! - Safely handle Zod errors
|
|
8
|
+
|
|
9
|
+
Prevents bugs where errors without the `.received` props would through and cause builds to fail unnecessarily.
|
|
10
|
+
|
|
11
|
+
## 0.26.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#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.
|
|
16
|
+
|
|
17
|
+
- [#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`.
|
|
18
|
+
|
|
3
19
|
## 0.26.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/integrations/asides.ts
CHANGED
|
@@ -64,10 +64,20 @@ function transformUnhandledDirective(
|
|
|
64
64
|
index: number,
|
|
65
65
|
parent: Parent
|
|
66
66
|
) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
package/utils/error-map.ts
CHANGED
|
@@ -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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
52
|
+
return parsedData.data;
|
|
33
53
|
}
|
|
34
54
|
|
|
35
55
|
const errorMap: z.ZodErrorMap = (baseError, ctx) => {
|
|
@@ -123,7 +143,8 @@ const errorMap: z.ZodErrorMap = (baseError, ctx) => {
|
|
|
123
143
|
};
|
|
124
144
|
|
|
125
145
|
const getTypeOrLiteralMsg = (error: TypeOrLiteralErrByPathEntry): string => {
|
|
126
|
-
|
|
146
|
+
// received could be `undefined` or the string `'undefined'`
|
|
147
|
+
if (typeof error.received === 'undefined' || error.received === 'undefined') return 'Required';
|
|
127
148
|
const expectedDeduped = new Set(error.expected);
|
|
128
149
|
switch (error.code) {
|
|
129
150
|
case 'invalid_type':
|
package/utils/starlight-page.ts
CHANGED
|
@@ -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
|
-
|
|
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.'
|