Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 25, 2020

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Mar 22, 2020

Motivation

The sidebar category shorthand syntax only works for the 1st level (for example Guides).

I think it makes sense to generalize this syntax and allow it for deeply nested categories as well

module.exports = {
  docs: {
    Guides: [
      'creating-pages',
      {
        type: 'category',
        label: 'Docs',
        items: ['markdown-features', 'sidebar', 'versioning'],
      },
    ],
  },
};

can be shortened as

module.exports = {
  docs: {
    Guides: [
      'creating-pages',
      {
        Docs: ['markdown-features', 'sidebar', 'versioning'],
      },
    ],
  },
};

Have you read the Contributing Guidelines on pull requests?

YES

Test Plan

Jest tests written

Related PRs

N/A

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 22, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Mar 22, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 75ac6ee

https://deploy-preview-2444--docusaurus-2.netlify.com

@yangshun yangshun added the pr: new feature This PR adds a new API or behavior. label Mar 23, 2020
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @slorber! I really appreciate your efforts especially when this PR is so well-written. Unfortunately using objects for the sidebar is really bad design on v1's part due to the implicit relying of object keys order. The only reason we kept it in v2 is to maintain compatibility with v1. I might even want to kill allowing the object syntax entirely in v2, so we don't want to further encourage such syntax.

Any thoughts?

@slorber
Copy link
Collaborator Author

slorber commented Mar 24, 2020

Hi and thanks for the review.

I don't know if this should be added or not, so I let you decide.

To me the syntax looks convenient and safe, as long as it's documented that the object keys should be declared in correct order.

Afaik the order of keys is predictable in Node (didn't check Deno) and seems specified in ES6.
Didn't double check, but found this: https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/
It's worth checking but I guess all recent Node/Deno engines are likely to implement this ordering, unlike some older browsers.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much thanks!

@yangshun yangshun merged commit 201c663 into facebook:master Mar 25, 2020
@@ -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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will try to find a better text for this, as it seems specified in ES6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants