From 624f6208fac4a0bab06590e07ba93cfa93383835 Mon Sep 17 00:00:00 2001 From: Luiz Ferraz Date: Wed, 28 Feb 2024 00:02:17 -0300 Subject: [PATCH] Fix pagefind default --- .../__tests__/basics/config-errors.test.ts | 1 + packages/starlight/utils/user-config.ts | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/starlight/__tests__/basics/config-errors.test.ts b/packages/starlight/__tests__/basics/config-errors.test.ts index dae9b599b6b..934bbfba5a2 100644 --- a/packages/starlight/__tests__/basics/config-errors.test.ts +++ b/packages/starlight/__tests__/basics/config-errors.test.ts @@ -62,6 +62,7 @@ test('parses valid config successfully', () => { "locales": undefined, "pagefind": true, "pagination": true, + "prerender": true, "tableOfContents": { "maxHeadingLevel": 3, "minHeadingLevel": 2, diff --git a/packages/starlight/utils/user-config.ts b/packages/starlight/utils/user-config.ts index bf85bf6097e..171efa8cbaf 100644 --- a/packages/starlight/utils/user-config.ts +++ b/packages/starlight/utils/user-config.ts @@ -218,8 +218,13 @@ const UserConfigSchema = z.object({ prerender: z.boolean().default(true), }); -export const StarlightConfigSchema = UserConfigSchema.strict().transform( - ({ locales, defaultLocale, ...config }, ctx) => { +export const StarlightConfigSchema = UserConfigSchema.strict() + .transform((config) => ({ + ...config, + // Pagefind only defaults to true if prerender is also true. + pagefind: config.pagefind ?? config.prerender, + })) + .transform(({ locales, defaultLocale, ...config }, ctx) => { if (locales !== undefined && Object.keys(locales).length > 1) { // This is a multilingual site (more than one locale configured). // Make sure we can find the default locale and if not, help the user set it. @@ -242,8 +247,6 @@ export const StarlightConfigSchema = UserConfigSchema.strict().transform( return { ...config, - // Pagefind only defaults to true if prerender is also true. - pagefind: config.pagefind ?? config.prerender, /** Flag indicating if this site has multiple locales set up. */ isMultilingual: true, /** Full locale object for this site’s default language. */ @@ -267,8 +270,7 @@ export const StarlightConfigSchema = UserConfigSchema.strict().transform( }, locales: undefined, } as const; - } -); + }); export type StarlightConfig = z.infer; export type StarlightUserConfig = z.input;