Skip to content

Commit e8a6ab1

Browse files
committed
fix: algolia search doesn't work well at i18n mode
Add lang facetFilters presets by following VuePress's i18n design logic
1 parent 0fdac01 commit e8a6ab1

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

lib/default-theme/AlgoliaSearchBox.vue

+24-8
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,44 @@ export default {
1515
props: ['options'],
1616
1717
mounted () {
18-
this.initialize()
18+
this.initialize(this.options, this.$lang)
1919
},
2020
2121
methods: {
22-
initialize () {
22+
initialize (userOptions, lang) {
2323
Promise.all([
2424
import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.js'),
2525
import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.css')
2626
]).then(([docsearch]) => {
2727
docsearch = docsearch.default
28-
docsearch(Object.assign(this.options, {
29-
debug: true,
30-
inputSelector: '#algolia-search-input'
31-
}))
28+
const { algoliaOptions = {}} = userOptions
29+
docsearch(Object.assign(
30+
{},
31+
userOptions,
32+
{
33+
inputSelector: '#algolia-search-input',
34+
// #697 Make docsearch work well at i18n mode.
35+
algoliaOptions: Object.assign({
36+
'facetFilters': [`lang:${lang}`].concat(algoliaOptions.facetFilters || [])
37+
}, algoliaOptions)
38+
}
39+
))
3240
})
41+
},
42+
43+
update (options, lang) {
44+
this.$el.innerHTML = '<input id="algolia-search-input" class="search-query">'
45+
this.initialize(options, lang)
3346
}
3447
},
3548
3649
watch: {
50+
$lang (newValue) {
51+
this.update(this.options, newValue)
52+
},
53+
3754
options (newValue) {
38-
this.$el.innerHTML = '<input id="algolia-search-input" class="search-query">'
39-
this.initialize(newValue)
55+
this.update(newValue, this.$lang)
4056
}
4157
}
4258
}

0 commit comments

Comments
 (0)