Skip to content

Commit 0494463

Browse files
fashxpcmfcmf
authored andcommitted
feat: Add option to show parent categories path in search result
1 parent 8364771 commit 0494463

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ The following options are available (defaults are shown below):
7373
//
7474
// Do _not_ use Infinity, the value must be a JSON-serializable integer.
7575
indexDocSidebarParentCategories: 0,
76-
77-
// Includes parent categories path in search result
76+
77+
// Includes parent categories path in search result
7878
includeParentCategoriesInPageTitle: true,
7979

8080
// whether to index blog pages

packages/docusaurus-search-local/src/server/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ export const tokenize = (input) => lunr.tokenizer(input)
547547
indexDocSidebarParentCategories > 0 &&
548548
docSidebarParentCategories
549549
) {
550-
const clonedDocSidebarParentCategories = [... docSidebarParentCategories];
550+
const clonedDocSidebarParentCategories = [
551+
...docSidebarParentCategories,
552+
];
551553
sidebarParentCategories = clonedDocSidebarParentCategories
552554
.reverse()
553555
.slice(0, indexDocSidebarParentCategories)
@@ -577,16 +579,17 @@ export const tokenize = (input) => lunr.tokenizer(input)
577579
type,
578580
docSidebarParentCategories,
579581
}): MyDocument => {
580-
581582
let fullTitle = pageTitle;
582583

583584
if (
584-
includeParentCategoriesInPageTitle &&
585-
docSidebarParentCategories &&
586-
docSidebarParentCategories.length > 0
585+
includeParentCategoriesInPageTitle &&
586+
docSidebarParentCategories &&
587+
docSidebarParentCategories.length > 0
587588
) {
588-
fullTitle = docSidebarParentCategories
589-
.join(' > ') + ' > ' + pageTitle;
589+
fullTitle =
590+
docSidebarParentCategories.join(" > ") +
591+
" > " +
592+
pageTitle;
590593
}
591594

592595
return {
@@ -595,7 +598,7 @@ export const tokenize = (input) => lunr.tokenizer(input)
595598
sectionTitle,
596599
sectionRoute,
597600
type,
598-
}
601+
};
599602
}
600603
),
601604
index,

0 commit comments

Comments
 (0)