繁体   English   中英

Docusaurus 可以读取文件夹中的所有文件吗?

[英]Can Docusaurus read all files in a folder?

使用 Docusaurus sidebars.js 可以这样指定:

module.exports = {
  docs: [
    {
      type: 'category',
      label: 'Docs',
      items: [
        {
          type: 'category',
          label: 'Widgets',
          items: 
          [
            'widgets/getting-started',
            'widgets/create-a-page',
            'widgets/create-a-document',
            'widgets/create-a-blog-post',
            'widgets/markdown-features',
            'widgets/thank-you',
          ],
        },
        {
          type: 'category',
          label: 'Next category',
          items: 
          [
            'next/getting-started'
          ]
        }        
      ]
    },
  ],
};

这意味着我需要将我创建的每个文件都放入 sidemenu.js。 是否可以只放置通配符,例如*.*并动态读取文件夹中的所有文件?

摘自 Docusaurus 文档( https://docusaurus.io/docs/sidebar )

Docusaurus 可以根据您的文件系统结构自动创建侧边栏:每个文件夹都会创建一个侧边栏类别。

Docusaurus 将自动生成的项目转换为侧边栏切片:文档和类别类型的项目列表。

type SidebarItemAutogenerated = {
  type: 'autogenerated';
  dirName: string; // Source folder to generate the sidebar slice from (relative to docs)
};

Docusaurus 可以从您的 docs 文件夹生成侧边栏:

侧边栏.js:

module.exports = {
  myAutogeneratedSidebar: [
    {
      type: 'autogenerated',
      dirName: '.', // '.' means the current docs folder
    },
  ],
};

您还可以在侧边栏中使用多个自动生成的项目,并将它们与常规侧边栏项目交错:

侧边栏.js:

module.exports = {
  mySidebar: [
    'intro',
    {
      type: 'category',
      label: 'Tutorials',
      items: [
        'tutorial-intro',
        {
          type: 'autogenerated',
          dirName: 'tutorials/easy', // Generate sidebar slice from docs/tutorials/easy
        },
        'tutorial-medium',
        {
          type: 'autogenerated',
          dirName: 'tutorials/advanced', // Generate sidebar slice from docs/tutorials/hard
        },
        'tutorial-end',
      ],
    },
    {
      type: 'autogenerated',
      dirName: 'guides', // Generate sidebar slice from docs/guides
    },
    {
      type: 'category',
      label: 'Community',
      items: ['team', 'chat'],
    },
  ],
};

因此,在上面的示例中,对于您的示例,您应该使用type: 'autogenerated' dirName: 'widgets'

我建议您仔细阅读侧边栏文档以正确应用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM