Skip to content

Commit 82eaecd

Browse files
author
微信公众号:储凡
authored
Merge pull request #148 from 142vip/feat/search-chinese
feat: 全局搜索框支持中文提示
2 parents 3be1930 + 4a883ac commit 82eaecd

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

docs/.vuepress/theme/i18n.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { ThemeLocaleData } from 'vuepress-theme-hope'
2+
import type { SearchProLocaleData } from 'vuepress-plugin-search-pro'
23
import { NotFoundMsgList } from './constant'
34

45
/**
56
* 支持中文
67
* 参考:https://theme-hope.vuejs.press/zh/config/i18n.html
78
*/
8-
const localCN: ThemeLocaleData = {
9+
const themeLocalCN: ThemeLocaleData = {
910
lang: 'zh-CN',
1011
navbarLocales: {
1112
langName: '简体中文',
@@ -76,5 +77,26 @@ const localCN: ThemeLocaleData = {
7677
* 自定义语言,支持文案
7778
*/
7879
export const i18n = {
79-
'/': localCN,
80+
'/': themeLocalCN,
81+
}
82+
83+
/**
84+
* 搜索框支持中文
85+
* 参考:https://plugin-search-pro.vuejs.press/zh/config.html#locales
86+
*/
87+
export const searchProCNLocals: SearchProLocaleData = {
88+
placeholder: '请输入需要搜索的关键字',
89+
search: '搜索文档',
90+
searching: '搜索中',
91+
cancel: '取消',
92+
select: '选择',
93+
navigate: '切换',
94+
exit: '关闭',
95+
loading: '正在努力搜索中...',
96+
queryHistory: '搜素文字历史',
97+
resultHistory: '搜索结果',
98+
emptyHistory: '没有搜索历史',
99+
emptyResult: '无法找到相关结果',
100+
defaultTitle: '搜索文档',
101+
autocomplete: '自动补齐',
80102
}

docs/.vuepress/theme/theme.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { hopeTheme } from 'vuepress-theme-hope'
22
import { AUTHOR_INFO, COPYRIGHT, FOOTER_HTML_INFO } from './constant'
3-
import { i18n } from './i18n'
3+
import { i18n, searchProCNLocals } from './i18n'
44
import navbar from './navbar'
55
import sidebar from './sidebar'
66

@@ -159,19 +159,10 @@ export const themeConfig = {
159159
},
160160
},
161161
searchPro: {
162-
// 索引全部内容
163-
indexContent: true,
164-
// 为分类和标签添加索引
165-
customFields: [
166-
{
167-
getter: (page: any) => page.frontmatter.category,
168-
formatter: '分类:$content',
169-
},
170-
{
171-
getter: page => page.frontmatter.tag,
172-
formatter: '标签:$content',
173-
},
174-
],
162+
// 参考:https://plugin-search-pro.vuejs.press/zh/config.html#locales
163+
locales: {
164+
'/': searchProCNLocals,
165+
},
175166
},
176167
// 代码高亮:https://theme-hope.vuejs.press/zh/guide/feature/code-block.html
177168
shiki: {

0 commit comments

Comments
 (0)