diff --git a/src/core/route/hash.js b/src/core/route/hash.js index 417ae96ae..fb441f0b5 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 3baf3bc64..455314f97 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 bindEvents () { +function doSearch (value) { 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.title}

-

${post.content}

-
` - }) - $panel.classList.add('show') - $panel.innerHTML = html || `

${NO_DATA_TEXT}

` + if (!value) { + $panel.classList.remove('show') + $panel.innerHTML = '' + return } + const matchs = search(value) + + let html = '' + matchs.forEach(post => { + html += `
+

${post.title}

+

${post.content}

+
` + }) + + $panel.classList.add('show') + $panel.innerHTML = html || `

${NO_DATA_TEXT}

` +} + +function bindEvents () { + const $search = dom.find('div.search') + const $input = dom.find($search, 'input') 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 6b9d3e167..8f6124cb0 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)) {