feat(search): Localization for no data tip, close #103
This commit is contained in:
parent
f3fc596951
commit
d3c9fbd124
4 changed files with 30 additions and 1 deletions
|
|
@ -27,6 +27,14 @@ By default, the hyperlink on the current page is recognized and the content is s
|
||||||
placeholder: {
|
placeholder: {
|
||||||
'/zh-cn/': '搜索',
|
'/zh-cn/': '搜索',
|
||||||
'/': 'Type to search'
|
'/': 'Type to search'
|
||||||
|
},
|
||||||
|
|
||||||
|
noData: 'No Results!',
|
||||||
|
|
||||||
|
// Localization
|
||||||
|
noData: {
|
||||||
|
'/zh-cn/': '找不到结果',
|
||||||
|
'/': 'No Results'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,14 @@
|
||||||
placeholder: {
|
placeholder: {
|
||||||
'/zh-cn/': '搜索',
|
'/zh-cn/': '搜索',
|
||||||
'/': 'Type to search'
|
'/': 'Type to search'
|
||||||
|
},
|
||||||
|
|
||||||
|
noData: 'No Results!',
|
||||||
|
|
||||||
|
// 支持本地化
|
||||||
|
noData: {
|
||||||
|
'/zh-cn/': '找不到结果',
|
||||||
|
'/': 'No Results'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { search } from './search'
|
import { search } from './search'
|
||||||
|
|
||||||
let dom
|
let dom
|
||||||
|
let NO_DATA_TEXT = ''
|
||||||
|
|
||||||
function style () {
|
function style () {
|
||||||
const code = `
|
const code = `
|
||||||
|
|
@ -98,7 +99,7 @@ function bindEvents () {
|
||||||
})
|
})
|
||||||
|
|
||||||
$panel.classList.add('show')
|
$panel.classList.add('show')
|
||||||
$panel.innerHTML = html || '<p class="empty">No Results!</p>'
|
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeId
|
let timeId
|
||||||
|
|
@ -122,6 +123,15 @@ function updatePlaceholder (text, path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateNoData (text, path) {
|
||||||
|
if (typeof text === 'string') {
|
||||||
|
NO_DATA_TEXT = text
|
||||||
|
} else {
|
||||||
|
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
|
||||||
|
NO_DATA_TEXT = text[match]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function init (opts) {
|
export function init (opts) {
|
||||||
dom = Docsify.dom
|
dom = Docsify.dom
|
||||||
style()
|
style()
|
||||||
|
|
@ -131,5 +141,6 @@ export function init (opts) {
|
||||||
|
|
||||||
export function update (opts, vm) {
|
export function update (opts, vm) {
|
||||||
updatePlaceholder(opts.placeholder, vm.route.path)
|
updatePlaceholder(opts.placeholder, vm.route.path)
|
||||||
|
updateNoData(opts.noData, vm.route.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { init as initSearch } from './search'
|
||||||
|
|
||||||
const CONFIG = {
|
const CONFIG = {
|
||||||
placeholder: 'Type to search',
|
placeholder: 'Type to search',
|
||||||
|
noData: 'No Results!',
|
||||||
paths: 'auto',
|
paths: 'auto',
|
||||||
maxAge: 86400000 // 1 day
|
maxAge: 86400000 // 1 day
|
||||||
}
|
}
|
||||||
|
|
@ -17,6 +18,7 @@ const install = function (hook, vm) {
|
||||||
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
|
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
|
||||||
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
|
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
|
||||||
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
|
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
|
||||||
|
CONFIG.noData = opts.noData || CONFIG.noData
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAuto = CONFIG.paths === 'auto'
|
const isAuto = CONFIG.paths === 'auto'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue