feat(v2): allow nested sidebar category shorthand syntax (#2444)

* feat(v2): allow sidebar category shorthand syntax also for nested elements

* Update sidebars-category-shorthand.js

* Update sidebars-category-shorthand.js

Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
Sébastien Lorber 2020-03-25 11:59:51 -05:00 committed by GitHub
parent 85c124e3f1
commit 201c663318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 116 additions and 52 deletions

View file

@ -50,7 +50,7 @@ module.exports = {
};
```
If you don't want to rely on iteration order of JavaScript object keys for the category name, the following sidebar object is also equivalent of the above.
Keep in mind that EcmaScript does not guarantee `Object.keys({a,b}) === ['a','b']` (yet, this is generally true). If you don't want to rely on iteration order of JavaScript object keys for the category name, the following sidebar object is also equivalent of the above shorthand syntax.
```js
// sidebars.js
@ -221,7 +221,23 @@ module.exports = {
{
type: 'category',
label: 'Docs',
items: ['markdown-features', 'sidebar'],
items: ['markdown-features', 'sidebar', 'versioning'],
},
],
},
};
```
**Note**: it's possible to use the shorthand syntax to create nested categories:
```js
// sidebars.js
module.exports = {
docs: {
Guides: [
'creating-pages',
{
Docs: ['markdown-features', 'sidebar', 'versioning'],
},
],
},

View file

@ -19,9 +19,7 @@ module.exports = {
'styling-layout',
'static-assets',
{
type: 'category',
label: 'Docs',
items: ['markdown-features', 'sidebar', 'versioning'],
Docs: ['markdown-features', 'sidebar', 'versioning'],
},
'blog',
'search',