{"id":13725904,"url":"https://github.com/whoisryosuke/gatsby-documentation-starter","last_synced_at":"2025-09-16T03:48:06.777Z","repository":{"id":45043941,"uuid":"149685273","full_name":"whoisryosuke/gatsby-documentation-starter","owner":"whoisryosuke","description":"Automatically generate docs for React components using MDX, react-docgen, and GatsbyJS","archived":false,"fork":false,"pushed_at":"2022-01-12T22:48:18.000Z","size":1895,"stargazers_count":92,"open_issues_count":5,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-29T08:57:40.733Z","etag":null,"topics":["docs","documentation","documentation-generator","gatsbyjs","mdx","reactjs"],"latest_commit_sha":null,"homepage":"https://gatsby-documentation-starter.netlify.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whoisryosuke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-21T00:04:42.000Z","updated_at":"2025-01-14T05:40:36.000Z","dependencies_parsed_at":"2022-09-23T10:42:57.351Z","dependency_job_id":null,"html_url":"https://github.com/whoisryosuke/gatsby-documentation-starter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/whoisryosuke/gatsby-documentation-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whoisryosuke%2Fgatsby-documentation-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whoisryosuke%2Fgatsby-documentation-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whoisryosuke%2Fgatsby-documentation-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whoisryosuke%2Fgatsby-documentation-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whoisryosuke","download_url":"https://codeload.github.com/whoisryosuke/gatsby-documentation-starter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whoisryosuke%2Fgatsby-documentation-starter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275358840,"owners_count":25450443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docs","documentation","documentation-generator","gatsbyjs","mdx","reactjs"],"created_at":"2024-08-03T01:02:40.405Z","updated_at":"2025-09-16T03:48:06.755Z","avatar_url":"https://github.com/whoisryosuke.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"![Screenshot of example Documentation website created with this template](thumbnail.png)\n\n# Gatsby Documentation Starter\n\nAutomatically generate documentation for your project using MDX, react-docgen, and GatsbyJS.\n\n## Features\n\n- 📝 [MDX](https://github.com/mdx-js/mdx) - Write your documentation in Markdown and include React components using JSX!\n- ♻️ [react-docgen](https://github.com/reactjs/react-docgen) - Automatically parses all your React components (functional, stateful, even stateless!) for JS Docblocks and Prop Types.\n- ⚛️ [GatsbyJS](http://gatsby.org) - Creates local GraphQL server to build static version of documentation (easily deployed on a CDN or GHPages, Netlify, etc)\n- 🗄 Props Table - Component for displaying component props in a table format\n- 🎛 Modular - Easily install inside existing projects!\n- ⚖️ Lightweight - Only what you need, no extra dependencies.\n\n## Quick Start\n\n**Install with Netlify**\n\n1. [![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/whoisryosuke/gatsby-documentation-starter/tree/example)\n\n\n**Install with Gatsby CLI**\n\n1. `gatsby new docs https://github.com/whoisryosuke/gatsby-documentation-starter/`\n\n**Custom install**\n\n1. `git clone https://github.com/whoisryosuke/gatsby-documentation-starter.git`\n1. Update `gatsby-config.js` with the location of your components + MDX _(see: \"Changing source folder\")_\n1. `npm install` inside project\n1. `npm run develop`\n1. View your documentation: http://localhost:8000\n\nCheck out the [example branch](https://github.com/whoisryosuke/gatsby-documentation-starter/tree/example) to see the source code of [the demo](https://gatsby-documentation-starter.netlify.com/).\n\n### Creating documentation\n\nDocumentation is sourced from two places: component source code and MDX files.\n\n```\nsrc\n└── components\n    └── Button\n        ├── Button.js\n        └── Button.mdx\n```\n\n**React-docgen** grabs any JS Docblocks you write for your React classes/functions (`Button.js`), as well as the Prop Types. These are displayed on your documentation page, with the props displayed in a table.\n\nInside your **MDX** file you can write additional documentation with JSX examples. You can also specify the page slug here (a **page name** and **category**). Your pages will be generated as `http://yoursite.com/\u003ccategory\u003e/\u003cpageName\u003e`.\n\nIn order for your component data to show up, you need an MDX file for the component - and the page name and component name in the docblock need to match.\n\n```js\n/**\n * ComponentTitle\n**/\nclass ComponentName extends React.Component {}\n```\n\n```md\n---\nname: ComponentTitle\nmenu: CategoryName\n---\n```\n\n\u003e Creates a page for the component located at http://localhost:8000/categoryname/componentname\n\n## Documentation\n\n## Customizing sidebar navigation\n\nThe sidebar navigation is generated from two places: a JSON config with static pages, and component MDX files. The static pages are displayed before the components.\n\nTo customize the static pages, go to `gatsby-config.js` and edit the `sidebar` object inside the `siteMetadata` config. Each page is represented as an object with a slug (the URL) and title:\n\n```json\n  siteMetadata: {\n    title: 'Gatsby Documentation Starter',\n    sidebar: {\n      pages: [\n        {\n          slug: '/about',\n          title: 'about',\n        },\n      ],\n    },\n  },\n```\n\nThe component pages in the navigation are automatically generated by querying all components with MDX files. If you want to change this, see section: _\"Creating pages from react-docgen\"_\n\nYou can override all of this functionality inside `components/sidebar.js`.\n\n### Changing source folder\n\nAdd the relative location of your components and MDX files in `gatsby-config.js`. The default configuration is set to the `/src/components/` folder of your root project (which ideally should document every component):\n\n```js\n    {\n      resolve: `gatsby-source-filesystem`,\n      options: {\n        name: `components`,\n        path: `../src/components/`,\n      },\n    },\n```\n\nGatsby will load all the JS and MDX files inside this folder. Then using the \"transformer\" plugins, Gatsby creates GraphQL endpoints for both components and MDX (`allMdx` and `allComponentMetadata`).\n\n\u003e You can add as many file sources as you need. The transformer plugins will automatically group content based on their format (JS, MDX, etc), and it uses **all** the content that's loaded.\n\n### Adding to existing projects\n\nThis project is designed to be embedded inside existing projects.\n\n1. `git clone` this repo into your project as a `docs` subfolder.\n2. Optionally change the folder where components are loaded from _(see \"Changing source folder\")_\n3. `npm install \u0026\u0026 npm run develop`\n\n### Creating pages from react-docgen\n\nThis template is setup to generate pages based off MDX files in your project. This allows you to create a `Button.mdx` to document your `\u003cButton /\u003e`. \n\n\u003e It's not required to make pages based off MDX. You can use Gatsby's default routing configuration, which creates pages based on any `.js` files located in the `pages` subfolder.\n\nIf you don't plan on having MDX files for each component, you can easily swap over to using `react-docgen` data to generate pages. That way, you're ensured a documentation page for each component (instead of MDX file). _This isn't the only option either, Gatsby's flexibility allows you to use both `react-docgen` and MDX files if you wanted the best of both worlds_\n\n`gatsby-node.js`:\n\n```js\n/**\n * Implement Gatsby's Node APIs in this file.\n *\n * See: https://www.gatsbyjs.org/docs/node-apis/\n */\n\nconst path = require('path')\nconst componentWithMDXScope = require('gatsby-mdx/component-with-mdx-scope')\n\nexports.createPages = ({ graphql, actions }) =\u003e {\n  const { createPage } = actions\n  return new Promise((resolve, reject) =\u003e {\n    resolve(\n      graphql(\n        `\n          {\n            allComponentMetadata {\n              edges {\n                node {\n                  id\n                  displayName\n                  docblock\n                  doclets\n                  childrenComponentProp {\n                    name\n                    docblock\n                    required\n                    type {\n                      value\n                    }\n                    defaultValue {\n                      value\n                      computed\n                    }\n                  }\n                  composes\n                }\n              }\n            }\n          }\n        `\n      ).then(result =\u003e {\n        if (result.errors) {\n          console.log(result.errors)\n          reject(result.errors)\n        }\n        // Create blog posts pages.\n        result.data.allComponentMetadata.edges.forEach(async ({ node }) =\u003e {\n          createPage({\n            path: `/components/${node.displayName.toLowerCase()}`,\n            component: componentWithMDXScope(\n              path.resolve('./src/templates/posts.js'),\n              node.code.scope\n            ),\n            context: {\n              id: node.id,\n              name: node.displayName,\n            },\n          })\n        })\n      })\n    )\n  })\n}\n```\n\nWe query the components through the `react-docgen` endpoint and use those to generate pages (instead of MDX files). Then we alter the page template to query MDX by name _(located in the Markdown 'frontmatter')_, and component by ID (the vice versa of it's default setup):\n\n`templates/posts.js`:\n\n```js\nimport React, { Component } from 'react'\nimport { graphql } from 'gatsby'\nimport MDXRenderer from 'gatsby-mdx/mdx-renderer'\nimport { MDXProvider } from '@mdx-js/tag'\n\nimport Layout from '../components/layout'\nimport PropsTable from '../components/propstable'\n\nexport default class MDXRuntimeTest extends Component {\n  render() {\n    const { children, data, tableOfContents } = this.props\n    return (\n        \u003cMDXProvider\u003e\n          \u003cLayout\u003e\n            \u003cdiv className=\"content\"\u003e\n              {children}\n              \u003ch1\u003e{data.componentMetadata.displayName}\u003c/h1\u003e\n              \u003cp\u003e{data.componentMetadata.docblock}\u003c/p\u003e\n              \u003cMDXRenderer tableOfContents={tableOfContents}\u003e\n                {data.mdx.code.body}\n              \u003c/MDXRenderer\u003e\n              \u003ch2 style={{ marginTop: '2rem' }}\u003eProps:\u003c/h2\u003e\n              \u003cPropsTable\n                propMetaData={data.componentMetadata.childrenComponentProp}\n              /\u003e\n            \u003c/div\u003e\n          \u003c/Layout\u003e\n        \u003c/MDXProvider\u003e\n    )\n  }\n}\n\nexport const pageQuery = graphql`\n  query($id: String!, $name: String!) {\n    mdx(frontmatter: { name: { eq: $name } }) {\n      id\n      code {\n        body\n      }\n      tableOfContents\n    }\n    componentMetadata(id: { eq: $id }) {\n      id\n      displayName\n      docblock\n      doclets\n      childrenComponentProp {\n        name\n        docblock\n        required\n        parentType {\n          name\n        }\n        type {\n          value\n        }\n        defaultValue {\n          value\n          computed\n        }\n      }\n      composes\n    }\n  }\n`\n```\n\n## Credits\n\n- [GatsbyJS](http://gatsby.org)\n- [gatsby-mdx](https://github.com/ChristopherBiscardi/gatsby-mdx/)\n- [gatsby-transformer-react-docgen](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-react-docgen)\n- [gatsby-transformer-remark](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-remark)\n- [Style Guide Guide](http://bradfrost.github.io/style-guide-guide/)\n- [Mobile Button CSS](https://codepen.io/ainalem/pen/LJYRxz)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhoisryosuke%2Fgatsby-documentation-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhoisryosuke%2Fgatsby-documentation-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhoisryosuke%2Fgatsby-documentation-starter/lists"}