diff --git a/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx b/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx index 974eca6ce20a..44916fd33c99 100644 --- a/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx +++ b/packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx @@ -440,6 +440,7 @@ describe('isVisibleSidebarItem', () => { it('works with category', () => { const subCategoryAllUnlisted = testCategory({ href: '/sub-category-path', + linkUnlisted: true, items: [ { type: 'link', @@ -455,6 +456,7 @@ describe('isVisibleSidebarItem', () => { }, testCategory({ href: '/sub-sub-category-path', + linkUnlisted: true, items: [ { type: 'link', @@ -500,6 +502,22 @@ describe('isVisibleSidebarItem', () => { expect( isVisibleSidebarItem(categorySomeUnlisted, categorySomeUnlisted.href!), ).toBe(true); + + const categoryOnlyIndexListed = testCategory({ + href: '/category-only-index-listed', + items: [ + { + type: 'link', + href: '/sub-link-path', + label: 'Label', + unlisted: true, + }, + subCategoryAllUnlisted, + ], + }); + expect( + isVisibleSidebarItem(categoryOnlyIndexListed, '/nonexistentPath'), + ).toBe(true); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx b/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx index cb8500eccc00..0fff426231a8 100644 --- a/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx +++ b/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx @@ -168,6 +168,7 @@ export function isVisibleSidebarItem( case 'category': return ( isActiveSidebarItem(item, activePath) || + (typeof item.href !== 'undefined' && !item.linkUnlisted) || item.items.some((subItem) => isVisibleSidebarItem(subItem, activePath)) ); case 'link': diff --git a/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/index.mdx b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/index.mdx new file mode 100644 index 000000000000..13df3c402e7c --- /dev/null +++ b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/index.mdx @@ -0,0 +1,14 @@ +--- +unlisted: false +tags: [visibility, unlisted] +--- + +# Subcategory index listed + +Doc index, **listed**, but all the other category items are unlisted + +```mdx-code-block +import DocCardList from '@theme/DocCardList'; + + +``` diff --git a/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/unlisted1.mdx b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/unlisted1.mdx new file mode 100644 index 000000000000..d83816f21de6 --- /dev/null +++ b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/unlisted1.mdx @@ -0,0 +1,8 @@ +--- +unlisted: true +tags: [visibility, unlisted] +--- + +# Unlisted 1 + +Doc with unlisted front matter diff --git a/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/unlisted2.mdx b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/unlisted2.mdx new file mode 100644 index 000000000000..e19258446816 --- /dev/null +++ b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/subcategory-with-listed-index/unlisted2.mdx @@ -0,0 +1,8 @@ +--- +unlisted: true +tags: [visibility, unlisted] +--- + +# Unlisted 2 + +Doc with unlisted front matter diff --git a/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/unlisted-subcategory/index.mdx b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/unlisted-subcategory/index.mdx index 31f24b59c698..abb934b22417 100644 --- a/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/unlisted-subcategory/index.mdx +++ b/website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/unlisted-subcategory/index.mdx @@ -3,7 +3,7 @@ unlisted: true tags: [visibility, unlisted] --- -# Some Unlisteds - Subcategory index unlisted +# Subcategory index unlisted Doc with unlisted front matter