Skip to content

Commit

Permalink
fix: algolia search doesn't work well at i18n mode
Browse files Browse the repository at this point in the history
Add lang facetFilters presets by following VuePress's i18n design logic
  • Loading branch information
ulivz committed Aug 7, 2018
1 parent 0fdac01 commit e8a6ab1
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/default-theme/AlgoliaSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,44 @@ export default {
props: ['options'],
mounted () {
this.initialize()
this.initialize(this.options, this.$lang)
},
methods: {
initialize () {
initialize (userOptions, lang) {
Promise.all([
import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.js'),
import(/* webpackChunkName: "docsearch" */ 'docsearch.js/dist/cdn/docsearch.min.css')
]).then(([docsearch]) => {
docsearch = docsearch.default
docsearch(Object.assign(this.options, {
debug: true,
inputSelector: '#algolia-search-input'
}))
const { algoliaOptions = {}} = userOptions
docsearch(Object.assign(
{},
userOptions,
{
inputSelector: '#algolia-search-input',
// #697 Make docsearch work well at i18n mode.
algoliaOptions: Object.assign({
'facetFilters': [`lang:${lang}`].concat(algoliaOptions.facetFilters || [])
}, algoliaOptions)
}
))
})
},
update (options, lang) {
this.$el.innerHTML = '<input id="algolia-search-input" class="search-query">'
this.initialize(options, lang)
}
},
watch: {
$lang (newValue) {
this.update(this.options, newValue)
},
options (newValue) {
this.$el.innerHTML = '<input id="algolia-search-input" class="search-query">'
this.initialize(newValue)
this.update(newValue, this.$lang)
}
}
}
Expand Down

0 comments on commit e8a6ab1

Please sign in to comment.