Skip to content

Commit

Permalink
refactor: rename ignoreClasses to ignoreCssSelectors and allow any cs…
Browse files Browse the repository at this point in the history
…s selector instead of just classes
  • Loading branch information
Cyriuz committed Sep 8, 2023
1 parent e9f7794 commit 4e2bc60
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = {
| searchResultContextMaxLength | number | `50` | Set the max length of characters of each search result to show. |
| explicitSearchResultPath | boolean | `false` | Whether an explicit path to a heading should be presented on a suggestion template. |
| ignoreFiles | string \| RegExp \| (string \| RegExp)[] | `[]` | Set the match rules to ignore some routes. Put a string if you want an exact match, or put a regex if you want a partial match. Note: without the website base url. |
| ignoreClasses | string \| string[] | `[]` | A list of html classes to ignore when indexing each page. |
| ignoreCssSelectors | string \| string[] | `[]` | A list of css selectors to ignore when indexing each page. |
| searchBarShortcut | boolean | `true` | Whether to enable keyboard shortcut to focus in search bar. |
| searchBarShortcutHint | boolean | `true` | Whether to show keyboard shortcut hint in search bar. Disable it if you need to hide the hint while shortcut is still enabled. |
| searchBarPosition | `"auto"` \| `"left"` \| `"right"` | `"auto"` | The side of the navbar the search bar should appear on. By default, it will try to autodetect based on your docusaurus config according to [the docs](https://docusaurus.io/docs/api/themes/configuration#navbar-search). |
Expand Down
4 changes: 2 additions & 2 deletions docusaurus-search-local/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ export interface PluginOptions {
ignoreFiles?: string | RegExp | (string | RegExp)[];

/**
* A list of html classes to ignore when indexing each page.
* A list of css selectors to ignore when indexing each page.
*
* @default []
*/
ignoreClasses?: string | string[];
ignoreCssSelectors?: string | string[];

/**
* Whether to enable keyboard shortcut to focus in search bar.
Expand Down
2 changes: 1 addition & 1 deletion docusaurus-search-local/src/server/utils/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("parse", () => {
])("parse(...) should work", (html, type, doc) => {
expect(
parse(html, type, "", {
ignoreClasses: ["ignore"],
ignoreCssSelectors: [".ignore"],
} as ProcessedPluginOptions)
).toEqual(doc);
});
Expand Down
8 changes: 4 additions & 4 deletions docusaurus-search-local/src/server/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export function parse(
html: string,
type: "docs" | "blog" | "page",
url: string,
{ ignoreClasses }: ProcessedPluginOptions
{ ignoreCssSelectors }: ProcessedPluginOptions
): ParsedDocument {
const $ = cheerio.load(html);
// Remove copy buttons from code boxes
$('div[class^="mdxCodeBlock_"] button').remove();

if (ignoreClasses) {
for (const ignoreClass of ignoreClasses) {
$("." + ignoreClass).remove();
if (ignoreCssSelectors) {
for (const ignoreSelector of ignoreCssSelectors) {
$(ignoreSelector).remove();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("processPluginOptions", () => {
blogDir: "blog",
language: "en",
ignoreFiles: "test",
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarPosition: "auto",
},
{
Expand All @@ -23,7 +23,7 @@ describe("processPluginOptions", () => {
docsDir: [expect.toMatchPath("/tmp/docs")],
language: ["en"],
ignoreFiles: ["test"],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarPosition: "right",
},
],
Expand All @@ -35,7 +35,7 @@ describe("processPluginOptions", () => {
blogDir: "blog",
language: ["en", "zh"],
ignoreFiles: [/__meta__$/],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarPosition: "left",
},
{
Expand All @@ -45,7 +45,7 @@ describe("processPluginOptions", () => {
docsDir: [expect.toMatchPath("/tmp/docs")],
language: ["en", "zh"],
ignoreFiles: [/__meta__$/],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarPosition: "left",
},
],
Expand All @@ -70,7 +70,7 @@ describe("processPluginOptions", () => {
blogDir: "blog",
language: "en",
ignoreFiles: "test",
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarPosition: "auto",
},
{
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("processPluginOptions", () => {
docsDir: [expect.toMatchPath("/tmp/docs")],
language: ["en"],
ignoreFiles: ["test"],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarPosition: "left",
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function processPluginOptions(
ensureArray(config, "docsDir");
ensureArray(config, "blogDir");
ensureArray(config, "ignoreFiles");
ensureArray(config, "ignoreClasses");
ensureArray(config, "ignoreCssSelectors");
config.docsRouteBasePath = config.docsRouteBasePath.map((basePath) =>
basePath.replace(/^\//, "")
);
Expand Down
16 changes: 8 additions & 8 deletions docusaurus-search-local/src/server/utils/validateOptions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: [],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: true,
searchBarPosition: "auto",
Expand All @@ -79,7 +79,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: "file1",
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: true,
searchBarPosition: "auto",
Expand All @@ -106,7 +106,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: [/__meta__$/, "file1"],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: true,
searchBarPosition: "auto",
Expand All @@ -133,7 +133,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: [],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: true,
searchBarPosition: "auto",
Expand Down Expand Up @@ -171,7 +171,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 30,
ignoreFiles: [],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: false,
searchBarShortcutHint: true,
searchBarPosition: "auto",
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: [],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: false,
searchBarPosition: "auto",
Expand Down Expand Up @@ -239,7 +239,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: [],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: true,
searchBarPosition: "left",
Expand Down Expand Up @@ -276,7 +276,7 @@ describe("validateOptions", () => {
explicitSearchResultPath: false,
searchResultContextMaxLength: 50,
ignoreFiles: [],
ignoreClasses: [],
ignoreCssSelectors: [],
searchBarShortcut: true,
searchBarShortcutHint: true,
searchBarPosition: "left",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const schema = Joi.object<PluginOptions>({
searchResultContextMaxLength: Joi.number().default(50),
explicitSearchResultPath: Joi.boolean().default(false),
ignoreFiles: isArrayOfStringsOrRegExpsOrStringOrRegExp.default([]),
ignoreClasses: isStringOrArrayOfStrings.default([]),
ignoreCssSelectors: isStringOrArrayOfStrings.default([]),
searchBarShortcut: Joi.boolean().default(true),
searchBarShortcutHint: Joi.boolean().default(true),
searchBarPosition: Joi.string().default("auto"),
Expand Down
4 changes: 2 additions & 2 deletions docusaurus-search-local/src/shared/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export type ProcessedPluginOptions = Required<
| "docsDir"
| "blogDir"
| "ignoreFiles"
| "ignoreClasses"
| "ignoreCssSelectors"
>
> & {
docsRouteBasePath: string[];
Expand All @@ -152,7 +152,7 @@ export type ProcessedPluginOptions = Required<
docsDir: string[];
blogDir: string[];
ignoreFiles: (string | RegExp)[];
ignoreClasses: string[];
ignoreCssSelectors: string[];
};

export interface PostBuildData {
Expand Down

0 comments on commit 4e2bc60

Please sign in to comment.