Skip to content

Commit

Permalink
Fix pagefind default
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Feb 28, 2024
1 parent d9677b0 commit 624f620
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/starlight/__tests__/basics/config-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ test('parses valid config successfully', () => {
"locales": undefined,
"pagefind": true,
"pagination": true,
"prerender": true,
"tableOfContents": {
"maxHeadingLevel": 3,
"minHeadingLevel": 2,
Expand Down
14 changes: 8 additions & 6 deletions packages/starlight/utils/user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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. */
Expand All @@ -267,8 +270,7 @@ export const StarlightConfigSchema = UserConfigSchema.strict().transform(
},
locales: undefined,
} as const;
}
);
});

export type StarlightConfig = z.infer<typeof StarlightConfigSchema>;
export type StarlightUserConfig = z.input<typeof StarlightConfigSchema>;

0 comments on commit 624f620

Please sign in to comment.