Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Build a local search plugin #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/PluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,33 @@ export default class PluginAPI {
this.search.enabled = true
return this
}

enableLocalSearch() {
const entries = []
for (let x = 0; x < this.store.getters.sidebar.length; x++) {
const obj = this.store.getters.sidebar[x]
if (obj && obj.title && obj.link) {
entries.push({
title: obj.title,
link: obj.link
})
}
if (obj.children) {
for (let y = 0; y < obj.children.length; y++) {
const obj2 = obj.children[y]
entries.push(obj2)
}
}
}

this.search = {
handler: keyword => {
return entries.filter(value =>
value.title.toLowerCase().includes(keyword.toLowerCase())
)
}
}
this.search.enabled = true
return this
}
}
6 changes: 6 additions & 0 deletions src/plugins/search/localSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
name: 'localSearch',
extend(api) {
api.enableLocalSearch()
}
}