Docusaurus: Update the sidebar.js by a docusaurus lifecycle

Created on 23 Mar 2020  路  3Comments  路  Source: facebook/docusaurus

馃殌 Feature

I want to write a plugin that will update the sidebar.js

Motivation

I'm planning to write a plugin for docusaurus that will look to my components and generate the docs automatically using react-docgen. So I need a way to update the sidebar using this plugin.

feature wontfix

Most helpful comment

Yes - having the sidebar auto-generate based on the content, folder/file structure in /docs etc. would make content management so much easier.

All 3 comments

Yes - having the sidebar auto-generate based on the content, folder/file structure in /docs etc. would make content management so much easier.

@mnbf9rca Try this plugin, i've just published it to npm

https://github.com/acrobit/docusaurus-plugin-auto-sidebars

You can override the name or the order of folders in the sidebars.yaml file.

Plugins lifecycles are generic across the whole website, not coupled to any plugin, such as docs. So it wouldn't make sense to add a plugin lifecycle for updating sidebars. We either need to modify the existing docs plugin or something or build an entirely new docs plugin.

Alternatively, we could add a plugin lifecycle called initialization() where you can write your own code to generate a sidebars.js file, but you can easily add a command that does that yourself before you run yarn start/build in package.json.

{
  "scripts": {
    "start": "./generate-sidebars.js && docusaurus start",
    "build": "./generate-sidebars.js && docusaurus build"
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericnakagawa picture ericnakagawa  路  3Comments

JoelMarcey picture JoelMarcey  路  3Comments

lex111 picture lex111  路  3Comments

chandankumar4 picture chandankumar4  路  3Comments

cheercroaker picture cheercroaker  路  3Comments