-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frontmatter to hide page from sidebar autogeneration (#441)
Co-authored-by: HiDeoo <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]>
- Loading branch information
1 parent
73eb5e6
commit 0119a49
Showing
5 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@astrojs/starlight': minor | ||
--- | ||
|
||
Add support for hiding entries from an autogenerated sidebar: | ||
|
||
```md | ||
--- | ||
title: About this project | ||
sidebar: | ||
hidden: true | ||
--- | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/starlight/__tests__/sidebar/navigation-hidden.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { describe, expect, test, vi } from 'vitest'; | ||
import { getSidebar } from '../../utils/navigation'; | ||
|
||
vi.mock('astro:content', async () => | ||
(await import('../test-utils')).mockedAstroContent({ | ||
docs: [ | ||
['index.mdx', { title: 'Home Page' }], | ||
['environmental-impact.md', { title: 'Eco-friendly docs' }], | ||
['reference/configuration.md', { title: 'Config Reference' }], | ||
['reference/frontmatter.md', { title: 'Frontmatter Reference', sidebar: { hidden: true } }], | ||
['guides/components.mdx', { title: 'Components' }], | ||
], | ||
}) | ||
); | ||
|
||
describe('getSidebar', () => { | ||
test('excludes sidebar entries with hidden: true in frontmatter', () => { | ||
expect(getSidebar('/', undefined)).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"href": "/", | ||
"isCurrent": true, | ||
"label": "Home", | ||
"type": "link", | ||
}, | ||
{ | ||
"collapsed": false, | ||
"entries": [ | ||
{ | ||
"href": "/intro/", | ||
"isCurrent": false, | ||
"label": "Introduction", | ||
"type": "link", | ||
}, | ||
{ | ||
"href": "/next-steps/", | ||
"isCurrent": false, | ||
"label": "Next Steps", | ||
"type": "link", | ||
}, | ||
], | ||
"label": "Start Here", | ||
"type": "group", | ||
}, | ||
{ | ||
"collapsed": false, | ||
"entries": [ | ||
{ | ||
"href": "/reference/configuration/", | ||
"isCurrent": false, | ||
"label": "Config Reference", | ||
"type": "link", | ||
}, | ||
], | ||
"label": "Reference", | ||
"type": "group", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters