Skip to content

Commit

Permalink
feat: allow force enable search index even if noIndex: true is set
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Dec 19, 2023
1 parent 83b05a2 commit 327276b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module.exports = {
| searchContextByPaths | `(string \| { label: string \| Record<string, string>; path: string; } )[]` | `[]` | Provide an list of sub-paths as separate search context, E.g.: `["docs", "community", "legacy/resources"]`. It will create multiple search indexes by these paths. |
| hideSearchBarWithNoSearchContext | boolean | `false` | Whether to hide the search bar when no search context was matched. By default, if `searchContextByPaths` is set, pages which are not matched with it will be considered as with a search context of ROOT. By setting `hideSearchBarWithNoSearchContext: true`, these pages will be considered as with NO search context, and the search bar will be hidden. |
| useAllContextsWithNoSearchContext | boolean | `false` | Whether to show results from all the contexts if no context is provided. This option should not be used with `hideSearchBarWithNoSearchContext: true` as this would show results when there is no search context. This will duplicate indexes and might have a performance cost depending on the index sizes. |
| `forceIgnoreNoIndex` | boolean | `false` | Force enable search index even if `noIndex: true` is set, this also affects unlisted articles. |

### I18N

Expand Down
1 change: 1 addition & 0 deletions docusaurus-search-local/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare module "*/generated.js" {
)[];
export const hideSearchBarWithNoSearchContext: boolean;
export const useAllContextsWithNoSearchContext: boolean;
export const forceIgnoreNoIndex: boolean;
// These below are for mocking only.
export const __setLanguage: (value: string[]) => void;
export const __setRemoveDefaultStopWordFilter: (value: boolean) => void;
Expand Down
7 changes: 7 additions & 0 deletions docusaurus-search-local/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,11 @@ export interface PluginOptions {
* @default false
*/
useAllContextsWithNoSearchContext?: boolean;

/**
* Force enable search index even if noIndex: true is set, this also affects unlisted articles.
*
* @default false
*/
forceIgnoreNoIndex?: boolean;
}
4 changes: 2 additions & 2 deletions docusaurus-search-local/src/server/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export function parse(
html: string,
type: "docs" | "blog" | "page",
url: string,
{ ignoreCssSelectors }: ProcessedPluginOptions
{ ignoreCssSelectors, forceIgnoreNoIndex }: ProcessedPluginOptions
): ParsedDocument | null {
const $ = cheerio.load(html);

const robotsMeta = $('meta[name="robots"]');
if (robotsMeta.attr("content")?.includes("noindex")) {
if (!forceIgnoreNoIndex && robotsMeta.attr("content")?.includes("noindex")) {
// Unlisted content
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const schema = Joi.object<PluginOptions>({
),
hideSearchBarWithNoSearchContext: Joi.boolean().default(false),
useAllContextsWithNoSearchContext: Joi.boolean().default(false),
forceIgnoreNoIndex: Joi.boolean().default(false),
});

export function validateOptions({
Expand Down

0 comments on commit 327276b

Please sign in to comment.