vuejs / vuepress

📝 Minimalistic Vue-powered static site generator
https://vuepress.vuejs.org
MIT License
22.45k stars 4.78k forks source link

DocSearch Hooks #1143

Open julienvincent opened 5 years ago

julienvincent commented 5 years ago

Feature request

I would like to be able to provide hooks to the DocSearch client for controlling input/output of the algolia search. Currently all functions are stripped out of the config given to the web-app, preventing me from being able to properly use the DocSearch client.

What problem does this feature solve?

Better integration with DocSearch.

For my specific case my docs are internal and need to be scraped from localhost. This means all search results contain the localhost hostname and I need to use the transformData DocSearch hook to rewrite the base hostname.

What does the proposed API look like?

algolia: {
  apiKey: "",
  indexName: "",

  transformData: () => {},
  // other hooks
}

How should this be implemented in your opinion?

The config given to the client through @internal/siteData must not have functions stripped out

Are you willing to work on this yourself?**

Yes, I started looking into this but for the life of me cannot figure out the build chain. I would be more than happy to implement this but would need some assistance in figuring out how the @internal files are populated.

julienvincent commented 5 years ago

After a bit of digging I have found that I can achieve what I want through the App Level Enhancements API. For example:

// enhanceApp.js

export default ({ Vue, options, router, siteData }) => {
  siteData.themeConfig.algolia.transformData = suggestions => {
    return suggestions.map(function(suggestion) {
      // ...
    });
  };
};

This was a rather obscure to figure out and I only really clicked that siteData contained my config after reading the source-code and seeing this name being used elsewhere (i.e @internal/siteData).

I think something can still be done here to make it a bit clearer for other people on how to do these kinda things. Perhaps an FAQ section on adding functions to config?

manico commented 5 years ago

If we use our own algolia search index (different appId), is there a docs for vuepress on which data is required to be generated for search to work?