Fumadocs

工作区

在多个工作区使用 Fumadocs MDX。

概览

🌐 Overview

在 Fumadocs MDX 中,工作区指的是一个拥有自己配置和内容的独立项目。

index.mdx
test.mdx
source.config.ts
welcome.mdx
source.config.ts

值得了解

Fumadocs MDX 工作区并不仅限于包管理器中传统意义上的工作区。

他们不需要拥有自己的 package.json,只需要一个配置文件即可。

🌐 They do not need to have its own package.json, only a config file is needed.

要定义一个工作区,请添加:

🌐 To define a workspace, add:

source.config.ts
import { defineConfig } from 'fumadocs-mdx/config';

export default defineConfig({
  workspaces: {
    'my-workspace': {
      dir: 'my-workspace',
      config: await import('./my-workspace/source.config.ts'),
    },
  },
});

在工作区撰写内容时,请注意:

🌐 When writing content in a workspace, note that:

  • cwd 指的是当前工作区目录
  • 配置不会继承,工作区始终是独立的。

通过运行开发或构建服务器,你应该能看到来自所有工作区的集合条目被生成。

🌐 By running dev or build server, you should see collection entries from all workspaces to be generated.

访问收藏

🌐 Accessing Collections

你可以在 .source/{workspace}/* 访问工作区生成的文件。例如:

🌐 You can access the generated files of a workspace at .source/{workspace}/*. For example:

lib/source.ts
import { docs } from 'fumadocs-mdx:collections/my-workspace/server';

根工作区的输出位置未更改。

要在 Fumadocs 中整合多个来源,请使用 multiple

🌐 To integrate multiple sources in Fumadocs, use multiple:

lib/source.ts
import { loader, multiple } from 'fumadocs-core/source';
import { docs } from 'fumadocs-mdx:collections/server';
import * as MyWorkspace from 'fumadocs-mdx:collections/my-workspace/server';

export const source = loader(
  multiple({
    root: docs.toFumadocsSource(),
    'my-workspace': MyWorkspace.docs.toFumadocsSource(),
  }),
  {
    baseUrl: '/docs',
  },
);

使用时机

🌐 When to Use

在某些设置中,你可能会有多个 Fumadocs MDX 配置,每个配置都有自己的内容目录。

🌐 In some setups, you might have multiple Fumadocs MDX configs with their own content directory.

通过工作区,你可以将它们整合到一个 Fumadocs MDX 配置中,并访问每个工作区的所有集合。

🌐 With workspaces, you can integrate them into one Fumadocs MDX config, and access all collections of each workspace.

这对于像在多个仓库中存储内容这样的用例至关重要,一个简化的设置如下:

🌐 This is crucial for use cases like storing content across multiple repos, a simplified setup would be:

  • 让你的主要文档仓库为 AA,其他仓库为 TnT_n
  • 对于每个仓库 TnT_n
    • TnT_nAA 作为 git 子模块。
    • TnT_n 定义了自己的配置 source.config.ts 并独立工作。
    • 当对 TnT_n 中的内容进行提交时,会触发 GitHub 操作(或持续集成),从而在 AA 上创建一个新的部署。
  • 当在 AA 上触发部署时:
    • Fumadocs MDX 将每个 TnT_n 处理为一个工作区。
    • 每个工作区都会生成自己的集合条目,例如 fumadocs-mdx:collections/{repo}/server
    • Fumadocs loader() 将多个来源整合到一个平台中。

Last updated on

On this page