Skip to content

Commit 09d0f30

Browse files
committed
feat: allow force enable search index even if noIndex: true is set
Closes #385
1 parent 83b05a2 commit 09d0f30

File tree

6 files changed

+21
-2
lines changed

6 files changed

+21
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ module.exports = {
9797
| 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. |
9898
| 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. |
9999
| 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. |
100+
| `forceIgnoreNoIndex` | boolean | `false` | Force enable search index even if `noIndex: true` is set, this also affects unlisted articles. |
100101

101102
### I18N
102103

docusaurus-search-local/src/declarations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ declare module "*/generated.js" {
2626
)[];
2727
export const hideSearchBarWithNoSearchContext: boolean;
2828
export const useAllContextsWithNoSearchContext: boolean;
29+
export const forceIgnoreNoIndex: boolean;
2930
// These below are for mocking only.
3031
export const __setLanguage: (value: string[]) => void;
3132
export const __setRemoveDefaultStopWordFilter: (value: boolean) => void;

docusaurus-search-local/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,11 @@ export interface PluginOptions {
192192
* @default false
193193
*/
194194
useAllContextsWithNoSearchContext?: boolean;
195+
196+
/**
197+
* Force enable search index even if noIndex: true is set, this also affects unlisted articles.
198+
*
199+
* @default false
200+
*/
201+
forceIgnoreNoIndex?: boolean;
195202
}

docusaurus-search-local/src/server/utils/parse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export function parse(
1010
html: string,
1111
type: "docs" | "blog" | "page",
1212
url: string,
13-
{ ignoreCssSelectors }: ProcessedPluginOptions
13+
{ ignoreCssSelectors, forceIgnoreNoIndex }: ProcessedPluginOptions
1414
): ParsedDocument | null {
1515
const $ = cheerio.load(html);
1616

1717
const robotsMeta = $('meta[name="robots"]');
18-
if (robotsMeta.attr("content")?.includes("noindex")) {
18+
if (!forceIgnoreNoIndex && robotsMeta.attr("content")?.includes("noindex")) {
1919
// Unlisted content
2020
return null;
2121
}

docusaurus-search-local/src/server/utils/validateOptions.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe("validateOptions", () => {
5656
searchBarShortcut: true,
5757
searchBarShortcutHint: true,
5858
searchBarPosition: "auto",
59+
forceIgnoreNoIndex: false,
5960
},
6061
],
6162
[
@@ -83,6 +84,7 @@ describe("validateOptions", () => {
8384
searchBarShortcut: true,
8485
searchBarShortcutHint: true,
8586
searchBarPosition: "auto",
87+
forceIgnoreNoIndex: false,
8688
},
8789
],
8890
[
@@ -110,6 +112,7 @@ describe("validateOptions", () => {
110112
searchBarShortcut: true,
111113
searchBarShortcutHint: true,
112114
searchBarPosition: "auto",
115+
forceIgnoreNoIndex: false,
113116
},
114117
],
115118
[
@@ -137,6 +140,7 @@ describe("validateOptions", () => {
137140
searchBarShortcut: true,
138141
searchBarShortcutHint: true,
139142
searchBarPosition: "auto",
143+
forceIgnoreNoIndex: false,
140144
},
141145
],
142146
[
@@ -151,6 +155,7 @@ describe("validateOptions", () => {
151155
explicitSearchResultPath: false,
152156
searchResultContextMaxLength: 30,
153157
searchBarShortcut: false,
158+
forceIgnoreNoIndex: true,
154159
},
155160
{
156161
blogRouteBasePath: ["blog"],
@@ -175,6 +180,7 @@ describe("validateOptions", () => {
175180
searchBarShortcut: false,
176181
searchBarShortcutHint: true,
177182
searchBarPosition: "auto",
183+
forceIgnoreNoIndex: true,
178184
},
179185
],
180186
[
@@ -207,6 +213,7 @@ describe("validateOptions", () => {
207213
searchBarShortcut: true,
208214
searchBarShortcutHint: false,
209215
searchBarPosition: "auto",
216+
forceIgnoreNoIndex: false,
210217
},
211218
],
212219
[
@@ -245,6 +252,7 @@ describe("validateOptions", () => {
245252
searchBarPosition: "left",
246253
docsPluginIdForPreferredVersion: "product",
247254
searchContextByPaths: ["docs", "community"],
255+
forceIgnoreNoIndex: false,
248256
},
249257
],
250258
[
@@ -282,6 +290,7 @@ describe("validateOptions", () => {
282290
searchBarPosition: "left",
283291
docsPluginIdForPreferredVersion: "product",
284292
searchContextByPaths: ["docs", "community"],
293+
forceIgnoreNoIndex: false,
285294
},
286295
],
287296
])("validateOptions(...) should work", (options, config) => {

docusaurus-search-local/src/server/utils/validateOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const schema = Joi.object<PluginOptions>({
6060
),
6161
hideSearchBarWithNoSearchContext: Joi.boolean().default(false),
6262
useAllContextsWithNoSearchContext: Joi.boolean().default(false),
63+
forceIgnoreNoIndex: Joi.boolean().default(false),
6364
});
6465

6566
export function validateOptions({

0 commit comments

Comments
 (0)