Skip to content
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

add support for hooks functions, setting query from URL, search exclusion #10

Merged
merged 13 commits into from Oct 22, 2020

Conversation

bobheadxi
Copy link
Contributor

@bobheadxi bobheadxi commented May 25, 2020

  • Add support for external results, which opens the result in a new tab
  • Add support for functions, which provides an implementable interface for various hooks:
    • processSuggestions to augment, adjust, or manipulate the suggestions
    • onGoToSuggestion to perform actions whenever a result is clicked
  • Add support for the fontmatter property search: false to exclude a page from results
  • Add support for URL search parameter query for populating and focusing the search bar

@leo-buneev
Copy link
Owner

leo-buneev commented May 25, 2020

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.

@bobheadxi
Copy link
Contributor Author

@leo-buneev I'd be happy to - will update this PR and ping you with a nicer implementation 🚀

@bobheadxi
Copy link
Contributor Author

bobheadxi commented May 26, 2020

@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 ubclaunchpad/UBC-LAUNCH-PAD#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

@bobheadxi
Copy link
Contributor Author

@leo-buneev I tried out the readFileSync approach in my usage of this branch (ubclaunchpad/UBC-LAUNCH-PAD#84) and it works very nicely - see bdfea2e 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')),
    }],
  ]
}

@leo-buneev
Copy link
Owner

leo-buneev commented May 29, 2020

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!

@bobheadxi
Copy link
Contributor Author

Yeah I couldn't find a way to "persist" a user-provided function for callback :(

@bobheadxi bobheadxi changed the title add support for external links add support for external links and on-click callbacks Jun 2, 2020
@bobheadxi
Copy link
Contributor Author

@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 :)

@leo-buneev
Copy link
Owner

Feel free to continue here, it can be considered as part of the same feature

@bobheadxi bobheadxi changed the title add support for external links and on-click callbacks add support for external links, on-click callbacks, setting query from URL Sep 22, 2020
@bobheadxi
Copy link
Contributor Author

bobheadxi commented Sep 22, 2020

@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.

@bobheadxi
Copy link
Contributor Author

@leo-buneev I've cleaned up the PR description and documentation!

@bobheadxi bobheadxi changed the title add support for external links, on-click callbacks, setting query from URL add support for hooks functions, setting query from URL, search exclusion Sep 22, 2020
@leo-buneev leo-buneev merged commit e186625 into leo-buneev:master Oct 22, 2020
leo-buneev pushed a commit that referenced this pull request Oct 22, 2020
shout-star added a commit to shout-star/vuepress-plugin-fulltext-search that referenced this pull request Jan 27, 2021
* add support for external links

* add processSuggestions API

* document fs.readFileSync alternative

* expand api to include more functions

* support fontmatter search: false

* add support for setting query from URL param

* remove semicolons for consistency

* document search parameters

* document excluding pages

* improve functions documentation

* clean up readme intro

* add paths to example blocks

* Add support for Japanese

* Change naming for functionality added in leo-buneev#10

* Fix leo-buneev#22

* Fix leo-buneev#21

* Fix leo-buneev#2

* Bump version

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Co-authored-by: Leonid Buneev <buneev.leonid@gmail.com>
Co-authored-by: Leonid Buneev <leonid.buneev@tirecheck.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants