From b84fe21baa04e11cce20041d34545b69b43219c0 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Thu, 3 Dec 2020 17:35:29 +0800 Subject: [PATCH] feat(cli): support custom facetFilters --- .../site/desktop/components/SearchInput.vue | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/vant-cli/site/desktop/components/SearchInput.vue b/packages/vant-cli/site/desktop/components/SearchInput.vue index 92793710b..88b43abd3 100644 --- a/packages/vant-cli/site/desktop/components/SearchInput.vue +++ b/packages/vant-cli/site/desktop/components/SearchInput.vue @@ -26,9 +26,17 @@ export default { }, mounted() { - if (this.searchConfig) { + const { searchConfig } = this; + if (searchConfig) { + const { algoliaOptions } = searchConfig; + let facetFilters = [`lang:${this.lang}`]; + + if (algoliaOptions?.facetFilters) { + facetFilters = facetFilters.concat(algoliaOptions.facetFilters); + } + this.docsearchInstance = window.docsearch({ - ...this.searchConfig, + ...searchConfig, transformData: (hits) => { hits.forEach((hit) => { if (hit.anchor) { @@ -36,13 +44,14 @@ export default { hit.anchor = null; } }); - if (this.searchConfig.transformData) { - this.searchConfig.transformData(hits); + if (searchConfig.transformData) { + searchConfig.transformData(hits); } }, inputSelector: '.van-doc-search', algoliaOptions: { - facetFilters: [`lang:${this.lang}`], + ...algoliaOptions, + facetFilters, }, }); }