diff --git a/src/core/route/hash.js b/src/core/route/hash.js index 417ae96a..fb441f0b 100644 --- a/src/core/route/hash.js +++ b/src/core/route/hash.js @@ -12,7 +12,7 @@ function replaceHash (path) { const replaceSlug = cached(path => { return path .replace('#', '?id=') - .replace(/\?(\w+)=/g, (_, slug) => slug === 'id' ? '?id=' : `&${slug}=`) + // .replace(/\?(\w+)=/g, (_, slug) => slug === 'id' ? '?id=' : `&${slug}=`) }) /** * Normalize the current url diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index 3baf3bc6..455314f9 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -69,9 +69,9 @@ function style () { dom.appendTo(dom.head, style) } -function tpl (opts) { +function tpl (opts, defaultValue = '') { const html = - `` + + `` + '
' + '' const el = dom.create('div', html) @@ -81,29 +81,32 @@ function tpl (opts) { dom.before(aside, el) } +function doSearch (value) { + const $search = dom.find('div.search') + const $panel = dom.find($search, '.results-panel') + + if (!value) { + $panel.classList.remove('show') + $panel.innerHTML = '' + return + } + const matchs = search(value) + + let html = '' + matchs.forEach(post => { + html += `${post.content}
+${NO_DATA_TEXT}
` +} + function bindEvents () { const $search = dom.find('div.search') const $input = dom.find($search, 'input') - const $panel = dom.find($search, '.results-panel') - const doSearch = function (value) { - if (!value) { - $panel.classList.remove('show') - $panel.innerHTML = '' - return - } - const matchs = search(value) - - let html = '' - matchs.forEach(post => { - html += `${post.content}
-${NO_DATA_TEXT}
` - } let timeId // Prevent to Fold sidebar @@ -137,9 +140,12 @@ function updateNoData (text, path) { export function init (opts) { dom = Docsify.dom + const keywords = Docsify.route.parse().query.s + style() - tpl(opts) + tpl(opts, keywords) bindEvents() + keywords && setTimeout(_ => doSearch(keywords), 500) } export function update (opts, vm) { diff --git a/src/plugins/search/index.js b/src/plugins/search/index.js index 6b9d3e16..8f6124cb 100644 --- a/src/plugins/search/index.js +++ b/src/plugins/search/index.js @@ -9,7 +9,7 @@ const CONFIG = { } const install = function (hook, vm) { - const util = Docsify.util + const { util } = Docsify const opts = vm.config.search || CONFIG if (Array.isArray(opts)) {