cmfcmf / docusaurus-search-local

Offline / Local Search for Docusaurus v2. Try it live at:
https://cmfcmf.github.io/OpenWeatherMap-PHP-API/
MIT License
438 stars 67 forks source link

Add ignore pages option #104

Closed JulesBlm closed 1 year ago

JulesBlm commented 2 years ago

Same as https://github.com/cmfcmf/docusaurus-search-local/pull/87. I made a new branch to avoid the potentially messy merge with upstream since the repo structure has changed. I will close the previous PR.

This adds an option to ignore pages so that they will not be included in the search index. For example, a long changelog page can pollute the search results and it's nice to be able to exclude such a page from the search index.

If the url to be ignored is added without the version, like: /docs/getting-started/intro it will be ignored for all versions. So for this example, these pages will be ignored: /docs/1.0.0/getting-started/intro /docs/2.0.0/getting-started/intro

The baseUrl is automatically prepended. So with baseUrl: 'foo', setting ignore to ['/docs/bar'] will exclude the /foo/docs/bar page from the search index.

It shows a warning if pages are defined in ignore but were not encountered.

cmfcmf commented 2 years ago

Thank you for the updates! I added some basic tests for this in a separate branch, see https://github.com/cmfcmf/docusaurus-search-local/tree/ignore-tests. However, these new tests are currently failing, because ignoring /docs/doc2 will not ignore doc2 for all documentation versions -- /docs/next/doc2 is still part of the search index.

JulesBlm commented 2 years ago

Thank you for the updates! I added some basic tests for this in a separate branch, see https://github.com/cmfcmf/docusaurus-search-local/tree/ignore-tests. However, these new tests are currently failing, because ignoring /docs/doc2 will not ignore doc2 for all documentation versions -- /docs/next/doc2 is still part of the search index.

Strange! I will check it out

JulesBlm commented 2 years ago

I got a bit swamped in other work but it turns out I was wrong about this

If the url to be ignored is added without the version, like: /docs/getting-started/intro it will be ignored for all versions.

I thought generating versioned pages happened afterwards, but it doesn't. Is there a way to get all the version strings in server/index.ts? I tried splitting strings but there were too many edge cases to get the versions strings reliably. Is it a good idea to import them from versions.json?