Skip to content

Commit

Permalink
fix: make search locale-scoped (close #128)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 18, 2018
1 parent ad83169 commit 846eb59
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/default-theme/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 846eb59

Please sign in to comment.