提交 846eb590 编写于 作者: E Evan You

fix: make search locale-scoped (close #128)

上级 ad83169f
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册