From 5f871feb409ef39fcc0d6491033cda64dc64fc2b Mon Sep 17 00:00:00 2001 From: Christian Flach Date: Sun, 9 Jun 2024 15:01:27 +0200 Subject: [PATCH] feat: Add option to show parent categories path in search result --- README.md | 2 +- .../docusaurus-search-local/src/server/index.ts | 13 +++++-------- packages/example-docs/docusaurus.config.js | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0f95e98..84336c1 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The following options are available (defaults are shown below): indexDocSidebarParentCategories: 0, // Includes parent categories path in search result - includeParentCategoriesInPageTitle: true, + includeParentCategoriesInPageTitle: false, // whether to index blog pages indexBlog: true, diff --git a/packages/docusaurus-search-local/src/server/index.ts b/packages/docusaurus-search-local/src/server/index.ts index ff2e5e7..5e9ca0f 100644 --- a/packages/docusaurus-search-local/src/server/index.ts +++ b/packages/docusaurus-search-local/src/server/index.ts @@ -547,10 +547,7 @@ export const tokenize = (input) => lunr.tokenizer(input) indexDocSidebarParentCategories > 0 && docSidebarParentCategories ) { - const clonedDocSidebarParentCategories = [ - ...docSidebarParentCategories, - ]; - sidebarParentCategories = clonedDocSidebarParentCategories + sidebarParentCategories = [...docSidebarParentCategories] .reverse() .slice(0, indexDocSidebarParentCategories) .join(" "); @@ -586,10 +583,10 @@ export const tokenize = (input) => lunr.tokenizer(input) docSidebarParentCategories && docSidebarParentCategories.length > 0 ) { - fullTitle = - docSidebarParentCategories.join(" > ") + - " > " + - pageTitle; + fullTitle = [ + ...docSidebarParentCategories, + pageTitle, + ].join(" > "); } return { diff --git a/packages/example-docs/docusaurus.config.js b/packages/example-docs/docusaurus.config.js index 318668d..3102bbb 100644 --- a/packages/example-docs/docusaurus.config.js +++ b/packages/example-docs/docusaurus.config.js @@ -126,7 +126,8 @@ module.exports = { ], plugins: [ [require.resolve("@cmfcmf/docusaurus-search-local"), { - indexPages: true + indexPages: true, + includeParentCategoriesInPageTitle: true, }], ] };