From 846eb59064bdf1e54731353c65467c168b1dd428 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 18 Apr 2018 11:48:30 -0400 Subject: [PATCH] fix: make search locale-scoped (close #128) --- lib/default-theme/SearchBox.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/default-theme/SearchBox.vue b/lib/default-theme/SearchBox.vue index cf5d9fb969..2263ceb891 100644 --- a/lib/default-theme/SearchBox.vue +++ b/lib/default-theme/SearchBox.vue @@ -53,6 +53,7 @@ export default { const max = 5 const { pages } = this.$site + const localePath = this.$basepath const matches = item => ( item.title && item.title.toLowerCase().indexOf(query) > -1 @@ -61,6 +62,10 @@ export default { for (let i = 0; i < pages.length; i++) { if (res.length >= max) break const p = pages[i] + // filter out results that do not match current locale + if (this.getPageLocalePath(p) !== localePath) { + continue + } if (matches(p)) { res.push(p) } else if (p.headers) { @@ -86,8 +91,15 @@ export default { } }, methods: { - onClick () { - console.log('clicked') + getPageLocalePath (page) { + const { langs } = this.$site + for (let i = 0; i < langs.length; i++) { + const localePath = langs[i].path + if (localePath !== '/' && page.path.indexOf(localePath) === 0) { + return langs[i].path + } + } + return '/' }, onUp () { if (this.showSuggestions) {