Skip to content

feat(v2): allow user to customize/enhance the default sidebar items generator - #4658

Merged
slorber merged 4 commits into
masterfrom
slorber/sidebar-generator-receive-default-generator
Apr 21, 2021
Merged

slorber merged 4 commits into
masterfrom
slorber/sidebar-generator-receive-default-generator

Conversation

@slorber

@slorber slorber commented Apr 21, 2021

Copy link
Copy Markdown
Collaborator

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

netlify Bot commented Apr 21, 2021

Copy link
Copy Markdown

@netlify

netlify Bot commented Apr 21, 2021

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

⚡️ 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
Copy Markdown

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
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
…enerator (meta#4658)

* allow and document how to wrap/enhance the default docusaurus sidebar items generator

* improve doc

* doc

* doc
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