Skip to content

Commit 2bbd8b5

Browse files
committed
fix: search box does not work when themeConfig search provider is set (fixes #9)
1 parent ec84b45 commit 2bbd8b5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,21 @@ export default class VitePressI18n {
101101
}
102102

103103
// Search
104-
if (i18nOptions.searchProvider) {
105-
if (i18nOptions.searchProvider === 'local') {
106-
result.themeConfig.search.options.locales[
107-
locale === i18nOptions.rootLocale ? 'root' : label
108-
] = LOCAL_SEARCH_TRANSLATIONS[locale];
109-
} else {
110-
result.themeConfig.search.options.locales[
111-
locale === i18nOptions.rootLocale ? 'root' : label
112-
] = ALGOLIA_SEARCH_TRANSLATIONS[locale];
113-
}
104+
const currentSearchProvider =
105+
i18nOptions.searchProvider ?? vitePressOptions.themeConfig?.search?.provider;
106+
107+
if (currentSearchProvider === 'local') {
108+
result.themeConfig.search.options.locales[
109+
locale === i18nOptions.rootLocale ? 'root' : label
110+
] = LOCAL_SEARCH_TRANSLATIONS[locale];
111+
} else if (currentSearchProvider === 'algolia') {
112+
result.themeConfig.search.options.locales[
113+
locale === i18nOptions.rootLocale ? 'root' : label
114+
] = ALGOLIA_SEARCH_TRANSLATIONS[locale];
114115
}
115116

117+
delete vitePressOptions.themeConfig?.search;
118+
116119
const commonThemeConfig = LOCALES_TRANSLATIONS[locale];
117120

118121
if (vitePressOptions.themeConfig?.editLink?.pattern) {

0 commit comments

Comments
 (0)