diff --git a/README.md b/README.md index 1527eb9..786ea3c 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,8 @@ The following options are available (defaults are shown below): titleBoost: 5, contentBoost: 1, parentCategoriesBoost: 2, // Only used when indexDocSidebarParentCategories > 0 + // Add urls to be excluded from the search index + ignore: ['/docs/reference/changelog'] } } ``` diff --git a/packages/docusaurus-search-local/src/server/index.test.js b/packages/docusaurus-search-local/src/server/index.test.js index 98d3094..8291ea1 100644 --- a/packages/docusaurus-search-local/src/server/index.test.js +++ b/packages/docusaurus-search-local/src/server/index.test.js @@ -66,6 +66,7 @@ it("validates options correctly", () => { titleBoost: 10, contentBoost: 1, parentCategoriesBoost: 4, + ignore: ["/changelog"], }, }; diff --git a/packages/docusaurus-search-local/src/server/index.ts b/packages/docusaurus-search-local/src/server/index.ts index ab347f1..c92f0e1 100644 --- a/packages/docusaurus-search-local/src/server/index.ts +++ b/packages/docusaurus-search-local/src/server/index.ts @@ -90,6 +90,7 @@ type MyOptions = { titleBoost: number; contentBoost: number; parentCategoriesBoost: number; + ignore: string[]; }; }; @@ -143,6 +144,7 @@ const optionsSchema = Joi.object({ titleBoost: Joi.number().min(0).default(5), contentBoost: Joi.number().min(0).default(1), parentCategoriesBoost: Joi.number().min(0).default(2), + ignore: Joi.array().items(Joi.string()), }).default(), }); @@ -164,6 +166,7 @@ export default function cmfcmfDocusaurusSearchLocal( titleBoost, contentBoost, parentCategoriesBoost, + ignore, }, } = options; @@ -360,6 +363,10 @@ export const tokenize = (input) => lunr.tokenizer(input) `The route must start with the baseUrl ${baseUrl}, but was ${route}. This is a bug, please report it.` ); } + if (ignore?.includes(url)) { + // Do not index ignored page. + return []; + } if (route === "404.html") { // Do not index error page. return [];