> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJiYmI4YTNkOC04ODYyLTRmMWYtYTYzZi1jZTQyNGE5M2UyODUiLCJleHAiOjE3ODEzNDQyNzMsImlhdCI6MTc4MTM0Mzk3M30.zgzOovEmeXvIT1_vFC5BJlGbxvlex4oRmSl4fYyS3B4
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 多源文档

> 了解如何设置多源文档，让独立团队使用一致的品牌在共享域上发布，使用 Fern。

此功能仅适用于[企业计划](https://buildwithfern.com/pricing)。如需开始使用，请联系 [support@buildwithfern.com](mailto:support@buildwithfern.com)。

多源文档将单个文档站点发布到自定义域，分成多个子路径。每个子路径都来自自己的仓库，因此团队可以独立发布更新，而共享的[全局主题](/learn/docs/customization/global-themes)保持整个站点品牌的一致性。

## 工作原理

每个仓库在其 `docs.yml` 中声明一个在共享域下的唯一基础路径。从该仓库运行 `fern generate --docs` 仅更新其子路径——其他所有子路径保持不变。

有三个配置使其工作：

1. **`multi-source: true`** 在每个仓库的 `docs.yml` 中的实例上设置，其中 `url` 和 `custom-domain` 以相同的基础路径结尾。
2. **[全局主题](/learn/docs/customization/global-themes)** 存在于专用的控制仓库中，并通过名称从每个源仓库的 `docs.yml` 中引用。
3. **多仓库设置** 在 [Fern Dashboard](https://dashboard.buildwithfern.com) 中控制域的默认路径和搜索/Ask AI 范围。

例如，NVIDIA 的文档分布在多个独立仓库中，每个仓库都发布到 `docs.nvidia.com` 上自己的子路径：

* [docs.nvidia.com/nvcf](https://docs.nvidia.com/nvcf)
* [docs.nvidia.com/brev](https://docs.nvidia.com/brev)
* [docs.nvidia.com/aiperf](https://docs.nvidia.com/aiperf)
* [docs.nvidia.com/nemo/curator](https://docs.nvidia.com/nemo/curator)

每个子路径都是独立发布的，但最终用户看到的是一个统一的站点。

根 `docs.nvidia.com` 本身是 Fern 设置之外的单独站点——多源仅涵盖子路径。Fern 发布的着陆页是可选的（[示例](#example-a-live-multi-source-site)），任何子路径组合都可以，包括仅两个。

## 设置多源文档

控制仓库是一个专用的 Fern 项目，保存你的全局主题——每个源仓库继承的共享 logo、颜色、字体、布局和站点级设置。在其 `docs.yml` 中定义这些设置，然后导出并上传主题：

```bash
fern docs theme export
fern docs theme upload --name my-org-theme
```

查看[全局主题](/learn/docs/customization/global-themes)获取完整设置指南和主题控制的字段列表。

每个子路径都有自己的仓库（通常由不同团队拥有），与步骤 1 中的控制仓库分开。在每个仓库的 `docs.yml` 中：

* 通过名称引用全局主题：`global-theme: my-org-theme`。
* 声明一个带有 `multi-source: true` 和在共享域上唯一基础路径的实例。该基础路径必须出现在 `url` 和 `custom-domain` 的末尾。

例如，这里是同一共享域上的两个仓库——一个在 `/product-a`，一个在 `/product-b`：

```yaml docs.yml
global-theme: my-org-theme

instances:
  - url: example.docs.buildwithfern.com/product-a
    custom-domain: docs.example.com/product-a
    multi-source: true
```

```yaml docs.yml
global-theme: my-org-theme

instances:
  - url: example.docs.buildwithfern.com/product-b
    custom-domain: docs.example.com/product-b
    multi-source: true
```

每个仓库独立发布：

```bash
fern generate --docs
```

只有该仓库拥有的子路径会被更新。其他所有子路径都不受影响。

打开 [Fern Dashboard](https://dashboard.buildwithfern.com) 并选择你的顶级域（例如 `docs.example.com`）——这些设置适用于整个域，而不是每个子路径。在 **Settings** 标签页中，导航到 **Multi-repo settings** 卡片。

配置以下内容：

* **默认路径** *（可选）*——设置用户访问域的根目录时的着陆页。当 Fern 管理的页面应该作为根页面时设置此选项。例如，如果你的主页位于 `/home` 子路径，将默认路径设置为 `/home`，这样 `docs.example.com` 就会重定向到 `docs.example.com/home`。如果根目录不是 Fern 管理的，比如 NVIDIA 的 `docs.nvidia.com`（Fern 设置之外的单独营销站点），则跳过此设置。
* **搜索 / Ask AI 行为**——控制 [Ask Fern](/learn/docs/ai-features/ask-fern/overview) 和搜索如何在子路径之间工作。有两种模式可用：
  * **层级模式**——在 `/subpath` 下的搜索仅返回来自 `/subpath` 及其下层的结果。当每个子路径涵盖不同产品且用户期望范围限定的结果时使用。
  * **统一模式**——在任何子路径下的搜索返回来自所有子路径的结果。当子路径是单个产品的各个部分且用户受益于跨领域结果时使用。

![Fern Dashboard 中的多源设置](https://files.buildwithfern.com/fern.docs.buildwithfern.com/learn/3d2e47df3ec27727ea62e5ca7ac24e8be315faa7adb937846036d1391d75be8f/products/docs/pages/preview-publish/images/multi-repo.png)

## 示例：实时多源站点

在 [multi-source.docs.buildwithfern.com](https://multi-source.docs.buildwithfern.com) 浏览实时站点，在 [fern-api/docs-examples/multi-source](https://github.com/fern-api/docs-examples/tree/main/multi-source) 查看源码。

这是 NVIDIA 设置的替代形式：在根目录有一个 Fern 管理的主页，下面有团队子路径。该示例在一个共享域上使用六个独立的 `fern/` 项目——在 `/` 的主页、带有两个嵌套子项的 `/seeds` 团队中心，以及独立的 `/greenhouses` 和 `/nursery` 团队：

单位是每个子路径一个 `fern/` 文件夹，而不是每个子路径一个仓库。每个仓库一个子路径的布局（通常每个团队一个）是最常见的形式，但单个仓库中的多个 `fern/` 文件夹也可以工作。

所有六个项目都共享 `global-theme: plantstore-theme` 并设置 `multi-source: true`——它们仅在基础路径上有所不同。子路径本身可以包含嵌套的子路径：`/seeds/sunflower` 和 `/seeds/tomato` 是位于 `/seeds` 下的独立发布项目。

该示例使用 Fern 的预览域（`*.docs.buildwithfern.com`），所以没有设置 `custom-domain`。生产部署通常会为每个实例添加 `custom-domain: docs.example.com/...`。

```yaml homepage/fern/docs.yml
global-theme: plantstore-theme

instances:
  - url: multi-source.docs.buildwithfern.com
    multi-source: true

navigation:
  - page: Home
    path: ./pages/home.mdx
```

主页 `home.mdx` 可以使用卡片将用户引导到每个团队的文档：

```jsx home.mdx
<CardGroup>
  <Card title="Seeds" icon="fa-regular fa-seedling" href="/seeds">
    一个在 `/seeds/sunflower` 和 `/seeds/tomato` 有嵌套子项的中心。
  </Card>
  <Card title="Greenhouses" icon="fa-regular fa-warehouse" href="/greenhouses">
    气候控制和监控。
  </Card>
  <Card title="Nursery" icon="fa-regular fa-leaf" href="/nursery">
    植物护理和繁殖。
  </Card>
</CardGroup>
```

```yaml seeds/fern/docs.yml
global-theme: plantstore-theme

instances:
  - url: multi-source.docs.buildwithfern.com/seeds
    multi-source: true

navigation:
  - section: 开始使用
    contents:
      - page: 概览
        path: ./pages/overview.mdx
```

```yaml seeds-sunflower/fern/docs.yml
global-theme: plantstore-theme

instances:
  - url: multi-source.docs.buildwithfern.com/seeds/sunflower
    multi-source: true

navigation:
  - section: 开始使用
    contents:
      - page: 概览
        path: ./pages/overview.mdx
```

```yaml greenhouses/fern/docs.yml
global-theme: plantstore-theme

instances:
  - url: multi-source.docs.buildwithfern.com/greenhouses
    multi-source: true

navigation:
  - section: 开始使用
    contents:
      - page: 概览
        path: ./pages/overview.mdx
```

## 属性

当为 `true` 时，CLI 使用基础路径感知发布，使多个仓库可以在一个自定义域下共存。启用此功能时，`url` 和 `custom-domain` 必须共享相同的基础路径。

要应用的[全局主题](/learn/docs/customization/global-themes)的名称。CLI 在发布时从 Fern 的注册表获取指定主题，并将其品牌字段合并到本地 `docs.yml` 中。查看[主题控制的内容](/learn/docs/customization/global-themes#what-the-theme-controls)获取完整字段列表。