Skip to content

Commit 256b80f

Browse files
committed
feat(search): Localization for no data tip, close #103
1 parent 02c611b commit 256b80f

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

docs/plugins.md

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ By default, the hyperlink on the current page is recognized and the content is s
2727
placeholder: {
2828
'/zh-cn/': '搜索',
2929
'/': 'Type to search'
30+
},
31+
32+
noData: 'No Results!',
33+
34+
// Localization
35+
noData: {
36+
'/zh-cn/': '找不到结果',
37+
'/': 'No Results'
3038
}
3139
}
3240
}

docs/zh-cn/plugins.md

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
placeholder: {
2828
'/zh-cn/': '搜索',
2929
'/': 'Type to search'
30+
},
31+
32+
noData: 'No Results!',
33+
34+
// 支持本地化
35+
noData: {
36+
'/zh-cn/': '找不到结果',
37+
'/': 'No Results'
3038
}
3139
}
3240
}

src/plugins/search/component.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { search } from './search'
22

33
let dom
4+
let NO_DATA_TEXT = ''
45

56
function style () {
67
const code = `
@@ -98,7 +99,7 @@ function bindEvents () {
9899
})
99100

100101
$panel.classList.add('show')
101-
$panel.innerHTML = html || '<p class="empty">No Results!</p>'
102+
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
102103
}
103104

104105
let timeId
@@ -122,6 +123,15 @@ function updatePlaceholder (text, path) {
122123
}
123124
}
124125

126+
function updateNoData (text, path) {
127+
if (typeof text === 'string') {
128+
NO_DATA_TEXT = text
129+
} else {
130+
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
131+
NO_DATA_TEXT = text[match]
132+
}
133+
}
134+
125135
export function init (opts) {
126136
dom = Docsify.dom
127137
style()
@@ -131,5 +141,6 @@ export function init (opts) {
131141

132142
export function update (opts, vm) {
133143
updatePlaceholder(opts.placeholder, vm.route.path)
144+
updateNoData(opts.noData, vm.route.path)
134145
}
135146

src/plugins/search/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { init as initSearch } from './search'
33

44
const CONFIG = {
55
placeholder: 'Type to search',
6+
noData: 'No Results!',
67
paths: 'auto',
78
maxAge: 86400000 // 1 day
89
}
@@ -17,6 +18,7 @@ const install = function (hook, vm) {
1718
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
1819
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
1920
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
21+
CONFIG.noData = opts.noData || CONFIG.noData
2022
}
2123

2224
const isAuto = CONFIG.paths === 'auto'

0 commit comments

Comments
 (0)