Skip to content

feat(v2): auto-generated sidebars, frontmatter-less sites - #4582

Merged
slorber merged 53 commits into
masterfrom
slorber/autogen-sidebars
Apr 15, 2021
Merged

slorber merged 53 commits into
masterfrom
slorber/autogen-sidebars

Conversation

@slorber

@slorber slorber commented Apr 6, 2021 •

Copy link
Copy Markdown
Collaborator

Motivation

Fixes #3464

Good description of this PR here: #3464 (comment)

  • Make it easy to create a site without any sidebar, and infer the sidebar from the FS structure
  • Make it easy to have no frontmatter at all, and derive good metadata from FS naming conventions (file number prefixes)

Breaking changes:

  • A site without sidebars file will now autogenerate a sidebar automatically from the docs folder. Use an empty sidebars file if you want no sidebar at all.
  • By default, we strip numbers in front of folders/filenames, as numbers prefixes are often used to provide docs order: this could have unintended side-effects if you have existing docs starting with numbers.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

tests, preview, dogfooding

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Apr 6, 2021
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 6, 2021
@netlify

netlify Bot commented Apr 6, 2021 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Apr 6, 2021 •

Copy link
Copy Markdown

Size Change: +33 B (0%)

Total Size: 598 kB

Filename Size Change
website/build/assets/js/main.********.js 422 kB +33 B (0%)
ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.2 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.1 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 26.9 kB 0 B

compressed-size-action

@netlify

netlify Bot commented Apr 6, 2021 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Apr 7, 2021 •

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

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

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

@slorber slorber added the pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. label Apr 7, 2021
@slorber slorber changed the title feat(v2): auto-generated sidebars feat(v2): auto-generated sidebars, frontmatter-less sites Apr 9, 2021
@slorber
slorber marked this pull request as ready for review April 13, 2021 10:45
@slorber
slorber requested a review from lex111 as a code owner April 13, 2021 10:45
@ywjr

ywjr commented Apr 30, 2021

Copy link
Copy Markdown

Generating sidebar automatically is a good function. I suggest that when generating sidebar automatically, the system can add filtering rules to filter out some files (such as readme. md

@borekb

borekb commented May 12, 2021

Copy link
Copy Markdown

By default, we strip numbers in front of folders/filenames, as numbers prefixes are often used to provide docs order: this could have unintended side-effects if you have existing docs starting with numbers.

(emphasis mine) @slorber That is very true for us 😄. We have a numbered tutorial like this:

  • 01-intro
  • 02-build-ui
  • 03-fetch-data
  • etc.

The files keep working as 01-intro.md but URLs are suddenly without these numbers, leading to 404s 🙁.

Any way to work around this?

@slorber

slorber commented May 12, 2021

Copy link
Copy Markdown
Collaborator Author

@borekb not sure to understand why you want the numbers in the URLs?

In any case, you should be able to use a custom slug to add these numbers back, or simply disable the feature with numberPrefixParser: false in the docs plugin/preset config

@borekb

borekb commented May 12, 2021

Copy link
Copy Markdown

It's just how it was, the tutorial part of our docs site used numbers in the URLs. Thanks for the tip with numberPrefixParser!

@slorber
slorber deleted the slorber/autogen-sidebars branch August 17, 2021 17:50
position?: number;
collapsed?: boolean;

// TODO should we allow "items" here? how would this work? would an "autogenerated" type be allowed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@slorber Assuming based on this that I won't be able to do what I asked about in an earlier comment?
#3464 (comment)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No I don't think it's possible atm but we may add support for it if there's a good use-case exposed clearly, preferably with a concrete example showcasing the problem (seeing sources is better)

mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* POC of autogenerated sidebars

* use combine-promises utility lib

* autogenerated sidebar poc working

* Revert "autogenerated sidebar poc working"

This reverts commit c81da98

* POC of auto-generated sidebars for community docs

* update tests

* add initial test suite for autogenerated sidebars + fix some edge cases

* Improve autogen sidebars: strip more number prefixes in folder breadcrumb + slugs

* fix typo!

* Add tests for partially generated sidebars + fix edge cases + extract sidebar generation code

* Ability to read category metadatas file from a file in the category

* fix tests

* change position of API

* ability to extract number prefix

* stable system to enable position frontmatter

* fix tests for autogen sidebar position

* renamings

* restore community sidebars

* rename frontmatter position -> sidebar_position

* make sidebarItemsGenerator fn configurable

* minor changes

* rename dirPath => dirName

* Make the init template use autogenerated sidebars

* fix options

* fix docusaurus site: remove test docs

* add _category_ file to docs pathsToWatch

* add _category_ file to docs pathsToWatch

* tutorial: use sidebar_position instead of file number prefixes

* Adapt Docusaurus tutorial for autogenerated sidebars

* remove slug: /

* polish the homepage template

* rename _category_ sidebar_position to just "position"

* test for custom sidebarItemsGenerator fn

* fix category metadata + add link to report tutorial issues

* fix absolute path breaking tests

* fix absolute path breaking tests

* Add test for floating number sidebar_position

* add sidebarItemsGenerator unit tests

* add processSidebars unit tests

* Fix init template broken links

* windows test

* increase code translations test timeout

* cleanup mockCategoryMetadataFiles after windows test fixed

* update init template positions

* fix windows tests

* fix comment

* Add autogenerated sidebar items documentation + rewrite the full sidebars page doc

* add useful comment

* fix code block title
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: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuring the title of a sidebar link in sidebar.js in plugin-docs Auto generate sidebar according to the docs folder structure

5 participants