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

Auto-generate routes for components #7

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

fsmaia
Copy link

@fsmaia fsmaia commented Dec 7, 2021

Fixes #5.

I set an addRoute to create a route for each component, plus an index route.

These routes are wrapped by some layout components:

  • ReactDocLayout, which is basically a simplified copy of DocPageContent, that adds the navbar and a custom sidebar (I was unable to embed the routes into the existing sidebar automatically)
  • ReactComponentPage, which is the root route, calling the layout and rendering the children properly
  • ReactComponentItem, which is the component docs itself

The user can enable this behavior with a createRoutes flag, and also set a baseRoute route, in which the routes/links will be created.

@@ -8,7 +8,7 @@ export const useDynamicImport = (name: string): Props => {
let resolved = false;

import(`@docgen/${name}.json`)
.then(props => {
.then(({ props }) => {
Copy link
Author

Choose a reason for hiding this comment

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

I thought it was easier to update the component's createData with the whole metadata, not only the props.

): Plugin<ComponentDoc[]> {
const { generatedFilesDir } = context;

const pluginId = id ?? DEFAULT_PLUGIN_ID;
Copy link
Author

Choose a reason for hiding this comment

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

Inspired by docusaurus-plugin-openapi setup.

content.map(async component => {
const componentData = await createData(
`${component.displayName}.json`,
JSON.stringify(component)
Copy link
Author

Choose a reason for hiding this comment

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

This was the only breaking change: component instead of component.props

@fsmaia fsmaia changed the title Draft: Auto-generate routes for components Auto-generate routes for components Dec 8, 2021
@fsmaia
Copy link
Author

fsmaia commented Dec 8, 2021

Some screenshots of a local execution:
React docs home page:
image

React component docs:
image

@fsmaia
Copy link
Author

fsmaia commented Dec 8, 2021

@atomicpages, could you help me on how to proceed with global or route flags? I implemented the createRoutes behavior only on the else branch (no global and no route).

@tsironis
Copy link

Hello there! I saw this MR and it's exactly what I need to document an SDK that my team is working on.

Are there any plans on merging this one?

@fsmaia
Copy link
Author

fsmaia commented Mar 15, 2022

cc @atomicpages

@atomicpages
Copy link
Owner

👋 howdy, I'll dig into this more later in the week

@molanostephane
Copy link

molanostephane commented Aug 17, 2022

I think this PR deserve a merge 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Suggestion] Auto-generate mdx files for components
4 participants