-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Allow routes generated by addRoute to be listed in the plugin-content-docs sidebar #6067
Comments
As a general rule, plugins work in isolation: isolation of data, isolation of routes (they shouldn't shadow/overlap with each other). I believe you should enhance the docs plugin instead if you find that you need to reuse a lot of the layout and data. |
Do you mean that the And then the consumer plugin should find a way to register the sidebar entries, and also add |
Yes, the docs plugin shouldn't know about anything outside the routes it generated by itself. Typically, we assume that each plugin renders its data without touching other plugins' data. So if you find yourself needing to generate extra data for the docs page to consume, you should enhance the plugin instead: #4492 (comment) |
Ok, big thanks for the clarification! I read the issue carefully and ran the project locally. But I still can't figure out how to inject the Anyway, we can close the issue. |
The sidebars data are loaded in the |
The sidebar is a concept of the docs plugin. Even though the blog plugin also displays a sidebar, it's a totally different implementation. If you implement your own plugin with a sidebar, you have 2 choices:
You can leverage the docs plugin in 2 ways:
We don't have a good public API for plugin extension so for now the best is to either implement your own UI or generate docs at build time. |
Thank you both for your kind explanations! After deep-diving into the code, this issue, and plugins, I realized these two choices and chose to create my own sidebar. Just for curiosity, my actual contribution/ambition is to render docs for all the React components within a project: After all, it seems to me it's right to have a sidebar for each docgen tool (OpenAPI, Typedoc, react-docgen, etc), so I lost some interest in injecting routes into the docs sidebar (it would be a very extensive list, to say the least). Last, but not least, I still think that the docs plugin should be route-based instead of file-based, but I'm sure there are several implications, such as it would break the complete isolation perspective. |
Not sure what you mean here. For now routes are only generated using the files of the docs folder, but in the future we'd like to provide an API so that you could fetch docs and sync with a CMS, the files wouldn't necessarily need to exist on disc as long as the CMS is able to provide md string and eventually some frontmatter |
Actually, all the routes registered by As of a common web application, every route is a candidate to be listed in the sidebar (at least is up to the developer to list a route or not). However, if we think that the docs plugin has a dedicated sidebar instance, then it doesn't make sense to list allow routes from other sources to be listed there. |
Only docs-related routes appear in the docs sidebar. That wouldn't make any sense to have a blog post appear in the blog sidebar, nor our showcase page.
I don't believe it's true. If you look at CMS-built site there's generally some kind of item category so that pages are tagged and appear in a menu, but nothing is automatic and has to be implemented. |
Have you read the Contributing Guidelines on issues?
Description
Currently, when a plugin/theme uses
addRoute
to register dynamic routes, these routes cannot be used in the sidebar. Besides, when accessing them directly, they have no wrapping layout (header/sidebar).As we have an
autogenerated
sidebar item type, we could have a specific type to list all the sub-routes of a base route.Has this been requested on Canny?
https://docusaurus.io/feature-requests/p/allow-routes-generated-by-addroute-to-be-listed-in-the-plugin-content-docs-sideb
Motivation
For plugin developers, using
addRoute
is way more powerful than performing anfs.createFileSync
with a raw template, due to the following reasons:component
may be used instead of a raw component generatorcomponent
may be a part of the theme, and also be swizzled or overriddenThis resource would be extremely useful for producing API Reference, such as documenting all the React components in a project, or all the TS typings, in a extensible scalable way.
API design
Add a new
type
to SidebarItemConfig to list all the sub-routes within a route:Real-life example:
A custom plugin generating dynamic routes (simplified version):
A Docusaurus configuration:
And finally, a docusaurus sidebar configuration:
Have you tried building it?
As this affects
docusaurus-plugin-content-docs
, I'm afraid it can't be customized outside it.Also it seems that
content-docs
has its own way to determine if a route should be wrapped by the layout or not.Self-service
The text was updated successfully, but these errors were encountered: