From e6cd33c946eb6c82ec3aefed1f487cfeae1bf4b8 Mon Sep 17 00:00:00 2001 From: Wayne Ferrao Date: Thu, 23 Jan 2025 15:35:35 -0800 Subject: [PATCH] Add option to config that removes the See All Results link in the search results. --- .../src/client/theme/SearchBar/SearchBar.tsx | 5 ++++- docusaurus-search-local/src/declarations.ts | 1 + docusaurus-search-local/src/index.ts | 7 +++++++ docusaurus-search-local/src/server/utils/generate.ts | 8 ++++++++ .../src/server/utils/validateOptions.ts | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docusaurus-search-local/src/client/theme/SearchBar/SearchBar.tsx b/docusaurus-search-local/src/client/theme/SearchBar/SearchBar.tsx index 228fef10..fc004d4f 100644 --- a/docusaurus-search-local/src/client/theme/SearchBar/SearchBar.tsx +++ b/docusaurus-search-local/src/client/theme/SearchBar/SearchBar.tsx @@ -30,6 +30,7 @@ import { searchContextByPaths, hideSearchBarWithNoSearchContext, useAllContextsWithNoSearchContext, + removeSeeAllResults, } from "../../utils/proxiedGenerated"; import LoadingRing from "../LoadingRing/LoadingRing"; import { normalizeContextByPath } from "../../utils/normalizeContextByPath"; @@ -280,7 +281,9 @@ export default function SearchBar({ const a = searchFooterLinkElement({ query, isEmpty }); const div = document.createElement("div"); div.className = styles.hitFooter; - div.appendChild(a); + if(removeSeeAllResults === false){ + div.appendChild(a); + } return div; }, }, diff --git a/docusaurus-search-local/src/declarations.ts b/docusaurus-search-local/src/declarations.ts index 73d67666..6571bab0 100644 --- a/docusaurus-search-local/src/declarations.ts +++ b/docusaurus-search-local/src/declarations.ts @@ -13,6 +13,7 @@ declare module "*/generated.js" { export const explicitSearchResultPath: boolean; export const searchBarShortcut: boolean; export const searchBarShortcutHint: boolean; + export const removeSeeAllResults: boolean; export const searchBarPosition: "left" | "right"; export const docsPluginIdForPreferredVersion: string; export const indexDocs: boolean; diff --git a/docusaurus-search-local/src/index.ts b/docusaurus-search-local/src/index.ts index 91d9f95d..be2943fe 100644 --- a/docusaurus-search-local/src/index.ts +++ b/docusaurus-search-local/src/index.ts @@ -199,4 +199,11 @@ export interface PluginOptions { * @default false */ forceIgnoreNoIndex?: boolean; + + /** + * Whether to remove the see all results button. + * + * @default false + */ + removeSeeAllResults?: boolean; } diff --git a/docusaurus-search-local/src/server/utils/generate.ts b/docusaurus-search-local/src/server/utils/generate.ts index 2e987bad..a19969f3 100644 --- a/docusaurus-search-local/src/server/utils/generate.ts +++ b/docusaurus-search-local/src/server/utils/generate.ts @@ -20,6 +20,7 @@ export function generate(config: ProcessedPluginOptions, dir: string): string { searchContextByPaths, hideSearchBarWithNoSearchContext, useAllContextsWithNoSearchContext, + removeSeeAllResults, } = config; const indexHash = getIndexHash(config); const contents: string[] = []; @@ -28,6 +29,13 @@ export function generate(config: ProcessedPluginOptions, dir: string): string { removeDefaultStemmer )};` ); + + contents.push( + `export const removeSeeAllResults = ${JSON.stringify( + removeSeeAllResults + )};` + ); + if (highlightSearchTermsOnTargetPage) { contents.push( `export { default as Mark } from ${JSON.stringify( diff --git a/docusaurus-search-local/src/server/utils/validateOptions.ts b/docusaurus-search-local/src/server/utils/validateOptions.ts index 7a5d7ae1..9aac073a 100644 --- a/docusaurus-search-local/src/server/utils/validateOptions.ts +++ b/docusaurus-search-local/src/server/utils/validateOptions.ts @@ -32,6 +32,7 @@ const schema = Joi.object({ removeDefaultStopWordFilter: Joi.boolean().default(false), removeDefaultStemmer: Joi.boolean().default(false), highlightSearchTermsOnTargetPage: Joi.boolean().default(false), + removeSeeAllResults:Joi.boolean().default(false), searchResultLimits: Joi.number().default(8), searchResultContextMaxLength: Joi.number().default(50), explicitSearchResultPath: Joi.boolean().default(false),