Skip to content

Commit

Permalink
fix(docs): fix sidebar item visibility bug for category index (facebo…
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored Dec 10, 2024
1 parent 4966dce commit 91c0b5b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ describe('isVisibleSidebarItem', () => {
it('works with category', () => {
const subCategoryAllUnlisted = testCategory({
href: '/sub-category-path',
linkUnlisted: true,
items: [
{
type: 'link',
Expand All @@ -455,6 +456,7 @@ describe('isVisibleSidebarItem', () => {
},
testCategory({
href: '/sub-sub-category-path',
linkUnlisted: true,
items: [
{
type: 'link',
Expand Down Expand Up @@ -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);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
<DocCardList />
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
unlisted: true
tags: [visibility, unlisted]
---

# Unlisted 1

Doc with unlisted front matter
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
unlisted: true
tags: [visibility, unlisted]
---

# Unlisted 2

Doc with unlisted front matter
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ unlisted: true
tags: [visibility, unlisted]
---

# Some Unlisteds - Subcategory index unlisted
# Subcategory index unlisted

Doc with unlisted front matter

Expand Down

0 comments on commit 91c0b5b

Please sign in to comment.