Skip to content

Commit cdc390e

Browse files
authored
fix: add zh locale support for algolia search (#39)
1 parent 037496a commit cdc390e

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.changeset/healthy-shirts-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/doom": patch
3+
---
4+
5+
fix: add zh locale support for algolia search

src/shared/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const ACP_BASE = '/container_platform/'
22

33
export const FALSY_VALUES = new Set([
44
null,
5+
undefined,
56
'',
67
'0',
78
'false',

src/theme.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1+
import { useLang } from '@rspress/core/runtime'
12
import { Search as OriginalSearch } from '@rspress/core/theme'
2-
import { Search as AlgoliaSearch } from '@rspress/plugin-algolia/runtime'
3+
import {
4+
Search as AlgoliaSearch,
5+
ZH_LOCALES,
6+
} from '@rspress/plugin-algolia/runtime'
7+
import { useMemo } from 'react'
38

49
const Search =
510
process.env.ALGOLIA_APP_ID &&
611
process.env.ALGOLIA_API_KEY &&
712
process.env.ALGOLIA_INDEX_NAME
8-
? () => (
9-
<AlgoliaSearch
10-
docSearchProps={{
13+
? () => {
14+
const lang = useLang()
15+
const docSearchProps = useMemo(
16+
() => ({
1117
appId: process.env.ALGOLIA_APP_ID!,
1218
apiKey: process.env.ALGOLIA_API_KEY!,
1319
indexName: process.env.ALGOLIA_INDEX_NAME!,
14-
}}
15-
/>
16-
)
20+
searchParameters: {
21+
facetFilters: [`language:${lang}`],
22+
},
23+
}),
24+
[lang],
25+
)
26+
return (
27+
<AlgoliaSearch docSearchProps={docSearchProps} locales={ZH_LOCALES} />
28+
)
29+
}
1730
: OriginalSearch
1831

1932
// eslint-disable-next-line import-x/export

0 commit comments

Comments
 (0)