Skip to content

Commit

Permalink
feat: Add option to show parent categories path in search result
Browse files Browse the repository at this point in the history
  • Loading branch information
fashxp authored and cmfcmf committed Jun 9, 2024
1 parent 8364771 commit 0494463
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ The following options are available (defaults are shown below):
//
// Do _not_ use Infinity, the value must be a JSON-serializable integer.
indexDocSidebarParentCategories: 0,
// Includes parent categories path in search result

// Includes parent categories path in search result
includeParentCategoriesInPageTitle: true,

// whether to index blog pages
Expand Down
19 changes: 11 additions & 8 deletions packages/docusaurus-search-local/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ export const tokenize = (input) => lunr.tokenizer(input)
indexDocSidebarParentCategories > 0 &&
docSidebarParentCategories
) {
const clonedDocSidebarParentCategories = [... docSidebarParentCategories];
const clonedDocSidebarParentCategories = [
...docSidebarParentCategories,
];
sidebarParentCategories = clonedDocSidebarParentCategories
.reverse()
.slice(0, indexDocSidebarParentCategories)
Expand Down Expand Up @@ -577,16 +579,17 @@ export const tokenize = (input) => lunr.tokenizer(input)
type,
docSidebarParentCategories,
}): MyDocument => {

let fullTitle = pageTitle;

if (
includeParentCategoriesInPageTitle &&
docSidebarParentCategories &&
docSidebarParentCategories.length > 0
includeParentCategoriesInPageTitle &&
docSidebarParentCategories &&
docSidebarParentCategories.length > 0
) {
fullTitle = docSidebarParentCategories
.join(' > ') + ' > ' + pageTitle;
fullTitle =
docSidebarParentCategories.join(" > ") +
" > " +
pageTitle;
}

return {
Expand All @@ -595,7 +598,7 @@ export const tokenize = (input) => lunr.tokenizer(input)
sectionTitle,
sectionRoute,
type,
}
};
}
),
index,
Expand Down

0 comments on commit 0494463

Please sign in to comment.