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
cmfcmf committed Jun 9, 2024
1 parent 0494463 commit 5f871fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions packages/docusaurus-search-local/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
Expand Down Expand Up @@ -586,10 +583,10 @@ export const tokenize = (input) => lunr.tokenizer(input)
docSidebarParentCategories &&
docSidebarParentCategories.length > 0
) {
fullTitle =
docSidebarParentCategories.join(" > ") +
" > " +
pageTitle;
fullTitle = [
...docSidebarParentCategories,
pageTitle,
].join(" > ");
}

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/example-docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = {
],
plugins: [
[require.resolve("@cmfcmf/docusaurus-search-local"), {
indexPages: true
indexPages: true,
includeParentCategoriesInPageTitle: true,
}],
]
};

0 comments on commit 5f871fe

Please sign in to comment.