diff --git a/docs/plugins.md b/docs/plugins.md index 29f434874..3142694cd 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -27,6 +27,14 @@ By default, the hyperlink on the current page is recognized and the content is s placeholder: { '/zh-cn/': '搜索', '/': 'Type to search' + }, + + noData: 'No Results!', + + // Localization + noData: { + '/zh-cn/': '找不到结果', + '/': 'No Results' } } } diff --git a/docs/zh-cn/plugins.md b/docs/zh-cn/plugins.md index aa29eab90..5fa1530a4 100644 --- a/docs/zh-cn/plugins.md +++ b/docs/zh-cn/plugins.md @@ -27,6 +27,14 @@ placeholder: { '/zh-cn/': '搜索', '/': 'Type to search' + }, + + noData: 'No Results!', + + // 支持本地化 + noData: { + '/zh-cn/': '找不到结果', + '/': 'No Results' } } } diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index 524448c8e..219fc8dcd 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -1,6 +1,7 @@ import { search } from './search' let dom +let NO_DATA_TEXT = '' function style () { const code = ` @@ -98,7 +99,7 @@ function bindEvents () { }) $panel.classList.add('show') - $panel.innerHTML = html || '

No Results!

' + $panel.innerHTML = html || `

${NO_DATA_TEXT}

` } 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) { dom = Docsify.dom style() @@ -131,5 +141,6 @@ export function init (opts) { export function update (opts, vm) { updatePlaceholder(opts.placeholder, vm.route.path) + updateNoData(opts.noData, vm.route.path) } diff --git a/src/plugins/search/index.js b/src/plugins/search/index.js index e1962793f..6b9d3e167 100644 --- a/src/plugins/search/index.js +++ b/src/plugins/search/index.js @@ -3,6 +3,7 @@ import { init as initSearch } from './search' const CONFIG = { placeholder: 'Type to search', + noData: 'No Results!', paths: 'auto', maxAge: 86400000 // 1 day } @@ -17,6 +18,7 @@ const install = function (hook, vm) { CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto' CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge CONFIG.placeholder = opts.placeholder || CONFIG.placeholder + CONFIG.noData = opts.noData || CONFIG.noData } const isAuto = CONFIG.paths === 'auto'