Closed bobheadxi closed 3 years ago
Thanks! That feature looks sweet, let's make it official.
I'd prefer to add more abstract hook processSuggestions(suggestions, queryString, queryTerms)
in vuepress's settings, that will return new array of suggestions - can be useful for many scenarios, including yours.
Will be awesome if you'll find time to prepare it.
@leo-buneev I'd be happy to - will update this PR and ping you with a nicer implementation 🚀
@leo-buneev unfortunately, 5279837 is the only practical way to implement this API within the Vuepress plugin framework - let me know what you think! You can see one use case at https://github.com/ubclaunchpad/docs/pull/84
Personally, I don't think it's too bad - vuepress still throws up fairly informative errors on syntax mistakes within the code. You could also do things like using readFileSync to provide the function string
@leo-buneev I tried out the readFileSync
approach in my usage of this branch (https://github.com/ubclaunchpad/docs/pull/84) and it works very nicely - see https://github.com/leo-buneev/vuepress-plugin-fulltext-search/pull/10/commits/bdfea2eb6f2bbcebe06391051201c2589c767102 for the updated docs:
const fs = require('fs');
const { path } = require('@vuepress/shared-utils');
module.exports = {
plugins: [
['fulltext-search', {
processSuggestions: fs.readFileSync(path.resolve(__dirname, 'processSuggestions.js')),
}],
]
}
Wow, that looks more complicated than I thought. Later today I'll try to implement option as a regular function (still can't believe it isn't possible 😮), and if I'll be unsuccessfull will merge your PR. Thank you!
Yeah I couldn't find a way to "persist" a user-provided function for callback :(
@leo-buneev For our purposes I've expanded the API in fdeed1f to allow an onclick callback as well - I made the poor choice of opening the PR from a master branch, so please let me know if you would like me to make more granular PRs or just continue expanding on this feature in my fork :)
Feel free to continue here, it can be considered as part of the same feature
@leo-buneev any chance this might land one day? :) We've been running this in https://docs.ubclaunchpad.com with some non-trivial traffic for quite a while, and am quite content with the API defined here.
@leo-buneev I've cleaned up the PR description and documentation!
external
results, which opens the result in a new tabfunctions
, which provides an implementable interface for various hooks:processSuggestions
to augment, adjust, or manipulate the suggestionsonGoToSuggestion
to perform actions whenever a result is clickedsearch: false
to exclude a page from resultsquery
for populating and focusing the search bar