【问题标题】:How to include (import) markdown file content in Docusaurus V2?如何在 Docusaurus V2 中包含(导入)markdown 文件内容?
【发布时间】:2021-01-15 18:02:12
【问题描述】:

有没有办法在 Docusaurus V2 中将 markdown 文件内容包含到另一个 markdown 文件中?我正在尝试整理我的 docs 文件夹结构。

当我们创建一个降价文件时,例如在文档中,Docusaurus 会自动在其他一些项目文件中设置文件路径。我想知道如何使它与 docs 文件夹中的文件夹一起使用?

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

【问题讨论】:

    标签: docusaurus


    【解决方案1】:

    我不确定我是否完全理解您的问题,但您可以按照我的想法尽可能深入地嵌套内容。您必须相应地创建您的sidebars.js

    我有这样的事情:

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

    【讨论】:

    • 我希望能够将降价内容导入另一个降价文件。
    【解决方案2】:

    .md文件的扩展名更改为.mdx并安装zero-md

    $ npm install --save zero-md
    

    在 Frontmatter 之后的 .mdx 文件中添加 import ZeroMd from 'zero-md' 并将 <zero-md src='{address of markdown file which you want to render}'></zero-md> 放在您要呈现降价文件的位置。

    【讨论】:

      【解决方案3】:

      可以像这样在 .mdx 文件中完成,查看文档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} />
      

      【讨论】:

        猜你喜欢
        • 2021-06-24
        • 2017-05-27
        • 2020-09-13
        • 1970-01-01
        • 1970-01-01
        • 2016-10-12
        • 1970-01-01
        • 2020-10-13
        • 1970-01-01
        相关资源
        最近更新 更多