diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index 946cc015e..d1ed003a0 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -150,7 +150,14 @@ function doSearch(value) { return; } - const matchs = search(value); + let matchs = search(value); + + if ( + options.resultPreHanlder && + typeof options.resultPreHanlder === 'function' + ) { + matchs = options.resultPreHanlder(matchs); + } let html = ''; matchs.forEach(post => { diff --git a/src/plugins/search/index.js b/src/plugins/search/index.js index c3bdab96e..7be6ef477 100644 --- a/src/plugins/search/index.js +++ b/src/plugins/search/index.js @@ -11,6 +11,7 @@ const CONFIG = { hideOtherSidebarContent: false, namespace: undefined, pathNamespaces: undefined, + resultPreHanlder: undefined, }; const install = function (hook, vm) { @@ -29,6 +30,7 @@ const install = function (hook, vm) { opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent; CONFIG.namespace = opts.namespace || CONFIG.namespace; CONFIG.pathNamespaces = opts.pathNamespaces || CONFIG.pathNamespaces; + CONFIG.resultPreHanlder = opts.resultPreHanlder || CONFIG.resultPreHanlder; } const isAuto = CONFIG.paths === 'auto';