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 user to customize/enhance the default sidebar items generator #4658

Merged
merged 4 commits into from
Apr 21, 2021

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Apr 21, 2021

Motivation

Customize the sidebar items generator logic by reusing and enhancing the default sidebar items generator with yur own logic.

Fixes #4640

Here's an example to generate a sidebar in reverse order:

// Reverse the sidebar items ordering (including nested category items)
function reverseSidebarItems(items) {
  // Reverse items in categories
  const result = items.map(item => {
    if (item.type === "category") {
      return { ...item, items: reverseSidebarItems(item.items) };
    }
    return item;
  });
  // Reverse items at current level
  result.reverse();
  return result;
}

module.exports = {
  plugins: [
    [
      "@docusaurus/plugin-content-docs",
      {
        sidebarItemsGenerator: async function({
          defaultSidebarItemsGenerator,
          ...args
        }) {
          const sidebarItems = await defaultSidebarItemsGenerator(args);
          return reverseSidebarItems(sidebarItems);
        }
      }
    ]
  ]
};

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

tests

@netlify
Copy link

netlify bot commented Apr 21, 2021

[V1]

Built with commit 67ab5b0

https://deploy-preview-4658--docusaurus-1.netlify.app

@netlify
Copy link

netlify bot commented Apr 21, 2021

[V2]

Built with commit 67ab5b0

https://deploy-preview-4658--docusaurus-2.netlify.app

@github-actions
Copy link

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 80
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4658--docusaurus-2.netlify.app/

@github-actions
Copy link

Size Change: 0 B

Total Size: 630 kB

ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.5 kB 0 B
website/build/assets/js/main.********.js 453 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.3 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 27.1 kB 0 B

compressed-size-action

@slorber slorber changed the title feat(v2): user should be able to enhance the default sidebar items generator feat(v2): allow user to customize/enhance the default sidebar items generator Apr 21, 2021
@slorber slorber merged commit 792f4ac into master Apr 21, 2021
@slorber slorber deleted the slorber/sidebar-generator-receive-default-generator branch August 17, 2021 17:49
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.

[v2.0.0-alpha.73] autogenerated sidebars: have a stripNumberPrefixes option in config file?
2 participants