Skip to content

Commit 846eb59

Browse files
committed
fix: make search locale-scoped (close #128)
1 parent ad83169 commit 846eb59

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/default-theme/SearchBox.vue

+14-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default {
5353
5454
const max = 5
5555
const { pages } = this.$site
56+
const localePath = this.$basepath
5657
const matches = item => (
5758
item.title &&
5859
item.title.toLowerCase().indexOf(query) > -1
@@ -61,6 +62,10 @@ export default {
6162
for (let i = 0; i < pages.length; i++) {
6263
if (res.length >= max) break
6364
const p = pages[i]
65+
// filter out results that do not match current locale
66+
if (this.getPageLocalePath(p) !== localePath) {
67+
continue
68+
}
6469
if (matches(p)) {
6570
res.push(p)
6671
} else if (p.headers) {
@@ -86,8 +91,15 @@ export default {
8691
}
8792
},
8893
methods: {
89-
onClick () {
90-
console.log('clicked')
94+
getPageLocalePath (page) {
95+
const { langs } = this.$site
96+
for (let i = 0; i < langs.length; i++) {
97+
const localePath = langs[i].path
98+
if (localePath !== '/' && page.path.indexOf(localePath) === 0) {
99+
return langs[i].path
100+
}
101+
}
102+
return '/'
91103
},
92104
onUp () {
93105
if (this.showSuggestions) {

0 commit comments

Comments
 (0)