-
-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to add Search function #260
Comments
To add a search function you need to have a plugin that handles the search.
where entries is a list of all pages you want to make searchable. |
Had the same problem so I'll add this in case that's helpful for someone. I used @DeveloperBen function. First, you'll need to call your API to get the array with your data: // Fetch this from your API
var SearchResult = [
{title: 'Title', link: 'title1', label: 'Label is optional', description: 'Description is optional'},
{title: 'Another', link: 'another'},
{title: 'One more', link: 'one-more'},
]; Then, create a plugin object: const searchBar = entries => {
return {
name: 'searchBar',
extend(api) {
api.enableSearch(
{
handler: keyword => {
return entries.filter(value =>
value.title.toLowerCase().includes(keyword.toLowerCase()))
}
}
);
}
}
} Finally, enable plugin in Docute object and pass your array: plugins: [
searchBar(SearchResult)
], References |
Hi, i tryed the above example to add a searchbar, but it does not work. the field is there but the search does not work thanks for any help cheers Ludwig |
Hi, Developers.
Based on this issue, search function has been implemented. I have read the documentation, but still cannot understand about what I should do.
Is it possible for you to give me working example in script.js like in docu-starter.zip.
Some javascript code like...
.. will be really useful for me.
Thank you very much.
The text was updated successfully, but these errors were encountered: