dynamicDocs: require()

in site/gatsby-config.js [52:102]


        dynamicDocs: require('./dynamic-doc-config'),
        // 为每个文档添加元数据:它属于哪个类目
        // 每个文档都需要有一个类目,文档的访问路径就是`/类目name/文档name`
        // 类目还被用于给左侧导航栏分类、搜索结果分类
        patchDocInfo: docInfo => {
          // debugger

          // 调试指南:
          // 为vscode配置debug参数:新建`.vscode/launch.json`
          /*
            {
              "version": "0.2.0",
              "configurations": [
                {
                  "type": "node",
                  "request": "attach",
                  "name": "Attach",
                  "port": 9229
                }
              ]
            }
           */
          // npx gatsby clean && npx --node-arg=--inspect-brk gatsby develop
          // 然后打开vscode的debug面板
          // 即可在调试期间停在这个地方,查看docInfo的结构
          if (docInfo.type === 'doc') {
            if (docInfo.fileSystemCrawlerName === 'biz-comp-crawler') {
              return {
                category: 'biz-components',
              }
            }
            if (docInfo.fileSystemCrawlerName === 'base-comp-crawler') {
              return {
                category: 'base-components',
              }
            }
            if (docInfo.fileSystemCrawlerName === 'guides-crawler') {
              return {
                category: 'guides',
              }
            }
            if (docInfo.fileSystemCrawlerName === 'dev-kit-crawler') {
              return {
                category: 'dev-kit',
              }
            }
            throw new Error(
              `unexpected docInfo.fileSystemCrawlerName: ${docInfo.fileSystemCrawlerName}`
            )
          }
        },