orama icon indicating copy to clipboard operation
orama copied to clipboard

OramaPlugin for vitepress, additional options.

Open lazarusA opened this issue 1 year ago • 0 comments

Problem Description

At the moment, it looks like the plugin for vitepress only accepts analytics as a known options field. However, it looks like more options could be added, like schema, searchOptions, etc...

Proposed Solution

Currently, I was expecting this to work (without success) :

  vite: {
    plugins: [OramaPlugin({
      schema: {
        title: 'string',
        content: 'string',
        functionNames: 'string[]',
      },
      searchOptions: {
        boost: {
          title: 2,
          functionNames: 3,
        },
      },
      contentTransformer: (content) => {
        // This regex matches patterns like Name.func1 or Name1.name2.func2
        const regex = /(?:^|\s)((?:\w+\.)+(\w+))/g;
        const matches = [...content.content.matchAll(regex)];
        const functionNames = matches.map(match => match[2]); // Capture the last word after the period

        return {
          ...content,
          functionNames: [...new Set(functionNames)], // Remove duplicates
        }
      },
    })],
  },

any hints on how to achieved this? maybe a workaround?

Alternatives

No response

Additional Context

No response

lazarusA avatar Jun 24 '24 21:06 lazarusA