@astrojs/starlight 0.37.7 → 0.38.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 +70 -0
- package/components/ContentNotice.astro +1 -1
- package/components/MobileTableOfContents.astro +2 -2
- package/components/Page.astro +3 -3
- package/components/Select.astro +2 -2
- package/components/SocialIcons.astro +1 -1
- package/components/TableOfContents.astro +2 -2
- package/global.d.ts +9 -3
- package/index.ts +39 -1
- package/integrations/asides.ts +1 -1
- package/integrations/remark-rehype.ts +2 -11
- package/integrations/virtual-user-config.ts +31 -17
- package/integrations/vite-layer-order.ts +38 -35
- package/package.json +12 -148
- package/schema.ts +3 -9
- package/schemas/badge.ts +9 -8
- package/schemas/components.ts +1 -1
- package/schemas/expressiveCode.ts +0 -3
- package/schemas/favicon.ts +4 -6
- package/schemas/head.ts +3 -2
- package/schemas/hero.ts +1 -1
- package/schemas/i18n.ts +148 -153
- package/schemas/icon.ts +1 -1
- package/schemas/pagefind.ts +5 -4
- package/schemas/prevNextLink.ts +6 -8
- package/schemas/sidebar.ts +33 -27
- package/schemas/site-title.ts +4 -6
- package/schemas/social.ts +3 -2
- package/schemas/tableOfContents.ts +3 -3
- package/style/props.css +7 -2
- package/types.ts +1 -1
- package/user-components/Aside.astro +1 -1
- package/user-components/Card.astro +1 -1
- package/user-components/Icon.astro +1 -1
- package/user-components/LinkButton.astro +1 -1
- package/user-components/TabItem.astro +1 -1
- package/user-components/rehype-file-tree.ts +1 -1
- package/user-components/rehype-tabs.ts +1 -1
- package/utils/createTranslationSystem.ts +1 -1
- package/utils/error-map.ts +98 -57
- package/utils/navigation.ts +11 -10
- package/utils/plugins.ts +75 -40
- package/utils/routing/data.ts +3 -9
- package/utils/routing/index.ts +16 -24
- package/utils/routing/types.ts +5 -17
- package/utils/slugs.ts +11 -12
- package/utils/starlight-page.ts +13 -23
- package/utils/translations.ts +3 -4
- package/utils/user-config.ts +28 -65
- package/virtual.d.ts +6 -3
- /package/{components → components-internals}/Icons.ts +0 -0
- /package/{components → components-internals}/SidebarPersistState.ts +0 -0
- /package/{components → components-internals}/TableOfContents/TableOfContentsList.astro +0 -0
- /package/{components → components-internals}/TableOfContents/starlight-toc.ts +0 -0
package/utils/user-config.ts
CHANGED
|
@@ -14,24 +14,11 @@ import { BuiltInDefaultLocale } from './i18n';
|
|
|
14
14
|
|
|
15
15
|
const LocaleSchema = z.object({
|
|
16
16
|
/** The label for this language to show in UI, e.g. `"English"`, `"العربية"`, or `"简体中文"`. */
|
|
17
|
-
label: z
|
|
18
|
-
.string()
|
|
19
|
-
.describe(
|
|
20
|
-
'The label for this language to show in UI, e.g. `"English"`, `"العربية"`, or `"简体中文"`.'
|
|
21
|
-
),
|
|
17
|
+
label: z.string(),
|
|
22
18
|
/** The BCP-47 tag for this language, e.g. `"en"`, `"ar"`, or `"zh-CN"`. */
|
|
23
|
-
lang: z
|
|
24
|
-
.string()
|
|
25
|
-
.optional()
|
|
26
|
-
.describe('The BCP-47 tag for this language, e.g. `"en"`, `"ar"`, or `"zh-CN"`.'),
|
|
19
|
+
lang: z.string().optional(),
|
|
27
20
|
/** The writing direction of this language; `"ltr"` for left-to-right (the default) or `"rtl"` for right-to-left. */
|
|
28
|
-
dir: z
|
|
29
|
-
.enum(['rtl', 'ltr'])
|
|
30
|
-
.optional()
|
|
31
|
-
.default('ltr')
|
|
32
|
-
.describe(
|
|
33
|
-
'The writing direction of this language; `"ltr"` for left-to-right (the default) or `"rtl"` for right-to-left.'
|
|
34
|
-
),
|
|
21
|
+
dir: z.enum(['rtl', 'ltr']).optional().default('ltr'),
|
|
35
22
|
});
|
|
36
23
|
|
|
37
24
|
const UserConfigSchema = z.object({
|
|
@@ -39,10 +26,7 @@ const UserConfigSchema = z.object({
|
|
|
39
26
|
title: TitleConfigSchema(),
|
|
40
27
|
|
|
41
28
|
/** Description metadata for your website. Can be used in page metadata. */
|
|
42
|
-
description: z
|
|
43
|
-
.string()
|
|
44
|
-
.optional()
|
|
45
|
-
.describe('Description metadata for your website. Can be used in page metadata.'),
|
|
29
|
+
description: z.string().optional(),
|
|
46
30
|
|
|
47
31
|
/** Set a logo image to show in the navigation bar alongside or instead of the site title. */
|
|
48
32
|
logo: LogoConfigSchema(),
|
|
@@ -62,7 +46,7 @@ const UserConfigSchema = z.object({
|
|
|
62
46
|
social: SocialLinksSchema(),
|
|
63
47
|
|
|
64
48
|
/** The tagline for your website. */
|
|
65
|
-
tagline: z.string().optional()
|
|
49
|
+
tagline: z.string().optional(),
|
|
66
50
|
|
|
67
51
|
/** Configure the defaults for the table of contents on each page. */
|
|
68
52
|
tableOfContents: TableOfContentsSchema(),
|
|
@@ -71,7 +55,7 @@ const UserConfigSchema = z.object({
|
|
|
71
55
|
editLink: z
|
|
72
56
|
.object({
|
|
73
57
|
/** Set the base URL for edit links. The final link will be `baseUrl` + the current page path. */
|
|
74
|
-
baseUrl: z.
|
|
58
|
+
baseUrl: z.url().optional(),
|
|
75
59
|
})
|
|
76
60
|
.optional()
|
|
77
61
|
.default({}),
|
|
@@ -96,9 +80,10 @@ const UserConfigSchema = z.object({
|
|
|
96
80
|
|
|
97
81
|
// Error if parsing the language tag failed.
|
|
98
82
|
if (!normalizedLang) {
|
|
99
|
-
ctx.
|
|
100
|
-
code:
|
|
83
|
+
ctx.issues.push({
|
|
84
|
+
code: 'custom',
|
|
101
85
|
message: `Could not validate language tag "${lang}" at locales.${key}.lang.`,
|
|
86
|
+
input: lang,
|
|
102
87
|
});
|
|
103
88
|
return z.NEVER;
|
|
104
89
|
}
|
|
@@ -116,8 +101,7 @@ const UserConfigSchema = z.object({
|
|
|
116
101
|
}
|
|
117
102
|
return locales;
|
|
118
103
|
})
|
|
119
|
-
.optional()
|
|
120
|
-
.describe('Configure locales for internationalization (i18n).'),
|
|
104
|
+
.optional(),
|
|
121
105
|
|
|
122
106
|
/**
|
|
123
107
|
* Specify the default language for this site.
|
|
@@ -172,27 +156,22 @@ const UserConfigSchema = z.object({
|
|
|
172
156
|
const invalidPathRegex = /^\.?\/public\/.+$/;
|
|
173
157
|
const invalidPaths = paths.filter((path) => invalidPathRegex.test(path));
|
|
174
158
|
if (invalidPaths.length > 0) {
|
|
175
|
-
ctx.
|
|
159
|
+
ctx.issues.push({
|
|
176
160
|
code: 'custom',
|
|
177
161
|
message:
|
|
178
162
|
`These paths in your Starlight \`customCss\` config are invalid: ${invalidPaths.map((path) => `\`"${path}"\``).join(', ')}\n\n` +
|
|
179
163
|
`CSS files specified in \`customCss\` should be in the \`src/\` directory, not the \`public/\` directory.\n\n` +
|
|
180
164
|
`You should move these CSS files into the \`src/\` directory and update the path in \`customCss\` to match.`,
|
|
165
|
+
input: paths,
|
|
181
166
|
});
|
|
182
167
|
}
|
|
183
168
|
}),
|
|
184
169
|
|
|
185
170
|
/** Define if the last update date should be visible in the page footer. */
|
|
186
|
-
lastUpdated: z
|
|
187
|
-
.boolean()
|
|
188
|
-
.default(false)
|
|
189
|
-
.describe('Define if the last update date should be visible in the page footer.'),
|
|
171
|
+
lastUpdated: z.boolean().default(false),
|
|
190
172
|
|
|
191
173
|
/** Define if the previous and next page links should be visible in the page footer. */
|
|
192
|
-
pagination: z
|
|
193
|
-
.boolean()
|
|
194
|
-
.default(true)
|
|
195
|
-
.describe('Define if the previous and next page links should be visible in the page footer.'),
|
|
174
|
+
pagination: z.boolean().default(true),
|
|
196
175
|
|
|
197
176
|
/** The default favicon for your site which should be a path to an image in the `public/` directory. */
|
|
198
177
|
favicon: FaviconSchema(),
|
|
@@ -218,13 +197,10 @@ const UserConfigSchema = z.object({
|
|
|
218
197
|
components: ComponentConfigSchema(),
|
|
219
198
|
|
|
220
199
|
/** Will be used as title delimiter in the generated `<title>` tag. */
|
|
221
|
-
titleDelimiter: z
|
|
222
|
-
.string()
|
|
223
|
-
.default('|')
|
|
224
|
-
.describe('Will be used as title delimiter in the generated `<title>` tag.'),
|
|
200
|
+
titleDelimiter: z.string().default('|'),
|
|
225
201
|
|
|
226
202
|
/** Disable Starlight's default 404 page. */
|
|
227
|
-
disable404Route: z.boolean().default(false)
|
|
203
|
+
disable404Route: z.boolean().default(false),
|
|
228
204
|
|
|
229
205
|
/**
|
|
230
206
|
* Define whether Starlight pages should be prerendered or not.
|
|
@@ -234,10 +210,7 @@ const UserConfigSchema = z.object({
|
|
|
234
210
|
prerender: z.boolean().default(true),
|
|
235
211
|
|
|
236
212
|
/** Enable displaying a “Built with Starlight” link in your site’s footer. */
|
|
237
|
-
credits: z
|
|
238
|
-
.boolean()
|
|
239
|
-
.default(false)
|
|
240
|
-
.describe('Enable displaying a “Built with Starlight” link in your site’s footer.'),
|
|
213
|
+
credits: z.boolean().default(false),
|
|
241
214
|
|
|
242
215
|
/** Add middleware to process Starlight’s route data for each page. */
|
|
243
216
|
routeMiddleware: z
|
|
@@ -250,47 +223,36 @@ const UserConfigSchema = z.object({
|
|
|
250
223
|
const invalidPathRegex = /^\.?\/src\/middleware(?:\/index)?\.[jt]s$/;
|
|
251
224
|
const invalidPaths = middlewares.filter((middleware) => invalidPathRegex.test(middleware));
|
|
252
225
|
for (const invalidPath of invalidPaths) {
|
|
253
|
-
ctx.
|
|
226
|
+
ctx.issues.push({
|
|
254
227
|
code: 'custom',
|
|
255
228
|
message:
|
|
256
229
|
`The \`"${invalidPath}"\` path in your Starlight \`routeMiddleware\` config conflicts with Astro’s middleware locations.\n\n` +
|
|
257
230
|
`You should rename \`${invalidPath}\` to something else like \`./src/starlightRouteData.ts\` and update the \`routeMiddleware\` file path to match.\n\n` +
|
|
258
231
|
'- More about Starlight route middleware: https://starlight.astro.build/guides/route-data/#how-to-customize-route-data\n' +
|
|
259
232
|
'- More about Astro middleware: https://docs.astro.build/en/guides/middleware/',
|
|
233
|
+
input: middlewares,
|
|
260
234
|
});
|
|
261
235
|
}
|
|
262
|
-
})
|
|
263
|
-
.describe('Add middleware to process Starlight’s route data for each page.'),
|
|
236
|
+
}),
|
|
264
237
|
|
|
265
238
|
/** Configure features that impact Starlight’s Markdown processing. */
|
|
266
239
|
markdown: z
|
|
267
240
|
.object({
|
|
268
241
|
/** Define whether headings in content should be rendered with clickable anchor links. Default: `true`. */
|
|
269
|
-
headingLinks: z
|
|
270
|
-
.boolean()
|
|
271
|
-
.default(true)
|
|
272
|
-
.describe(
|
|
273
|
-
'Define whether headings in content should be rendered with clickable anchor links. Default: `true`.'
|
|
274
|
-
),
|
|
242
|
+
headingLinks: z.boolean().default(true),
|
|
275
243
|
/**
|
|
276
244
|
* Define additional directories where files should be processed by Starlight’s Markdown pipeline.
|
|
277
245
|
*
|
|
278
246
|
* Supports local directories relative to the root of your project, e.g. './src/data/comments/'.
|
|
279
247
|
* Content of the `docs` content collection is always processed by Starlight’s Markdown pipeline.
|
|
280
248
|
*/
|
|
281
|
-
processedDirs: z
|
|
282
|
-
.string()
|
|
283
|
-
.array()
|
|
284
|
-
.default([])
|
|
285
|
-
.describe(
|
|
286
|
-
'Define additional directories where files should be processed by Starlight’s Markdown pipeline. Default: `[]`.'
|
|
287
|
-
),
|
|
249
|
+
processedDirs: z.string().array().default([]),
|
|
288
250
|
})
|
|
289
|
-
.
|
|
290
|
-
.describe('Configure features that impact Starlight’s Markdown processing.'),
|
|
251
|
+
.prefault({}),
|
|
291
252
|
});
|
|
292
253
|
|
|
293
|
-
export const StarlightConfigSchema =
|
|
254
|
+
export const StarlightConfigSchema = z
|
|
255
|
+
.strictObject({ ...UserConfigSchema.shape })
|
|
294
256
|
.transform((config) => ({
|
|
295
257
|
...config,
|
|
296
258
|
// Pagefind only defaults to true if prerender is also true.
|
|
@@ -300,7 +262,7 @@ export const StarlightConfigSchema = UserConfigSchema.strict()
|
|
|
300
262
|
: config.pagefind,
|
|
301
263
|
}))
|
|
302
264
|
.refine((config) => !(!config.prerender && config.pagefind), {
|
|
303
|
-
|
|
265
|
+
error: 'Pagefind search is not supported with prerendering disabled.',
|
|
304
266
|
})
|
|
305
267
|
.transform(({ title, locales, defaultLocale, ...config }, ctx) => {
|
|
306
268
|
const configuredLocales = Object.keys(locales ?? {});
|
|
@@ -321,12 +283,13 @@ export const StarlightConfigSchema = UserConfigSchema.strict()
|
|
|
321
283
|
|
|
322
284
|
if (!defaultLocaleConfig) {
|
|
323
285
|
const availableLocales = configuredLocales.map((l) => `"${l}"`).join(', ');
|
|
324
|
-
ctx.
|
|
286
|
+
ctx.issues.push({
|
|
325
287
|
code: 'custom',
|
|
326
288
|
message:
|
|
327
289
|
'Could not determine the default locale. ' +
|
|
328
290
|
'Please make sure `defaultLocale` in your Starlight config is one of ' +
|
|
329
291
|
availableLocales,
|
|
292
|
+
input: locales,
|
|
330
293
|
});
|
|
331
294
|
return z.NEVER;
|
|
332
295
|
}
|
package/virtual.d.ts
CHANGED
|
@@ -8,8 +8,12 @@ declare module 'virtual:starlight/plugin-translations' {
|
|
|
8
8
|
export default PluginTranslations;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
// TODO:
|
|
12
|
-
//
|
|
11
|
+
// TODO: Technically, we could move back this module declaration to `virtual-internal.d.ts` when
|
|
12
|
+
// `utils/translations.ts` no longer need to import project context. Altho, we should not aim for
|
|
13
|
+
// such refactor right now as shipping Starlight in JavaScript rather than TypeScript will
|
|
14
|
+
// entirely eliminate such issue and the need for private and public declaration files for virtual
|
|
15
|
+
// modules.
|
|
16
|
+
// @see https://github.com/withastro/starlight/pull/3572
|
|
13
17
|
declare module 'virtual:starlight/project-context' {
|
|
14
18
|
const ProjectContext: {
|
|
15
19
|
root: string;
|
|
@@ -18,7 +22,6 @@ declare module 'virtual:starlight/project-context' {
|
|
|
18
22
|
build: {
|
|
19
23
|
format: import('astro').AstroConfig['build']['format'];
|
|
20
24
|
};
|
|
21
|
-
legacyCollections: boolean;
|
|
22
25
|
};
|
|
23
26
|
export default ProjectContext;
|
|
24
27
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|