How to include (import) markdown file content in Docusaurus V2?

Viewed 1254

Is there any way to include markdown file content into another markdown file in Docusaurus V2? I'm trying to organize my docs folder structure.

When we create a markdown file, e.g. in docs, Docusaurus automatically sets up the file path in some other project files. I'd like to know how do I make it works with folders into docs folder?

.
├── docc
│   ├── chapter1
│   │   ├── index.md
│   │   ├── session1.md
│   │   └── session2.md
│   └── chapter2
│       ├── index.md
│       ├── session1.md
│       └── session2.md
├── doc1.md
├── doc2.md
└── doc3.md
3 Answers

Change extension of .md file to .mdx and install zero-md.

$ npm install --save zero-md

In the .mdx file after Frontmatter add import ZeroMd from 'zero-md' and put <zero-md src='{address of markdown file which you want to render}'></zero-md> where you want to render the markdown file.

I am not sure if i understand your question fully, but you can nest content as deeply as you wish i think. You'll have to create your sidebars.js accordingly.

I have something like this:

module.exports = {
  someSidebar: {
    'Manual': [
      'intro',
      'login',
      'admin',
      {
        'Services': [
          'services/service1',
          'services/service2',
          'services/service3',
        ]
      }
    ]
  }
};

It can be done within .mdx files like this, check the docs here:

import License from './license.md' // Assumes an integration is used to compile MDX -> JS.
import Contributing from './docs/contributing.mdx'

# Hello world

<License components={props.components} />

---

<Contributing components={props.components} />
Related