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 ignore pages option #87

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
}
```
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-search-local/src/server/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ it("validates options correctly", () => {
titleBoost: 10,
contentBoost: 1,
parentCategoriesBoost: 4,
ignore: ["/changelog"],
},
};

Expand Down
7 changes: 7 additions & 0 deletions packages/docusaurus-search-local/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type MyOptions = {
titleBoost: number;
contentBoost: number;
parentCategoriesBoost: number;
ignore: string[];
};
};

Expand Down Expand Up @@ -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(),
});

Expand All @@ -164,6 +166,7 @@ export default function cmfcmfDocusaurusSearchLocal(
titleBoost,
contentBoost,
parentCategoriesBoost,
ignore,
},
} = options;

Expand Down Expand Up @@ -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 [];
Expand Down