> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI3YTg1YmU3ZC1kODllLTQxMDUtOTAzZi1hZDUzOTc4NGU1OTYiLCJleHAiOjE3NzgzMTAzMjYsImlhdCI6MTc3ODMxMDAyNn0.hZ_-UiogKMbOny3_WkhRuK1YfTvY47vh84SsWGfVbzs
>
> 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.

# 库文档生成器 <Badge type="note">Beta</Badge>

> 从您的 Python 或 C++ 库源代码生成 MDX 文档页面，并将其包含在您的 Fern Docs 站点中。

库文档生成器解析您的 **Python 或 C++** 库源代码，为模块、类、函数、方法和参数生成 MDX 文档页面。生成的页面包含交叉引用链接和层次化导航，并直接集成到您的 Fern Docs 站点中。

## 配置

<Steps>
  <Step title="在 `docs.yml` 中定义您的库">
    在您的 `docs.yml` 文件中添加 `libraries` 条目。每个库都需要一个 `input` 源（要解析的仓库）、一个 `output.path`（生成的 MDX 文件的写入位置）和一个 `lang`（`python` 或 `cpp`）。

    ```yaml docs.yml
    libraries:
      plant-core:
        input:
          git: https://github.com/acme/plant-core-cpp # 仓库 URL
          subpath: packages/plant-core # 可选，用于 monorepo
        output:
          path: ./static/plant-core-docs # 相对于 fern/ 目录
        lang: cpp # python 或 cpp
        config:
          doxyfile: ./Doxyfile # 可选，仅限 C++
    ```

    <Info>
      您可以在同一个文件中[定义多个库](#multiple-libraries-example)。
    </Info>
  </Step>

  <Step title="添加到导航">
    在您的导航中指向一个 [`folder:` 条目](/learn/docs/configuration/navigation#add-a-folder)，该条目指向您设置为 `output.path` 的相同目录。Fern 会发现该文件夹中的每个 MDX 文件，并将其子文件夹结构映射到侧边栏部分。

    ```yaml docs.yml {8}
    navigation:
      - section: 快速入门
        contents:
          - page: 概述
            path: ./pages/overview.mdx
      - section: Plant SDK 参考
        contents:
          - folder: ./static/plant-sdk-docs
    ```
  </Step>

  <Step title="生成库文档">
    运行 CLI 命令从您的库源代码生成 MDX 文件：

    ```bash
    fern docs md generate
    ```

    该命令会克隆仓库，解析源代码，并将 MDX 文件写入输出目录。

    <Tip>
      如果您配置了多个库，`fern docs md generate` 会并行处理所有库。使用 `--library plant-sdk` 仅为特定库生成文档。
    </Tip>
  </Step>

  <Step title="本地预览">
    运行本地开发服务器，查看您的库文档以及站点的其余部分：

    ```bash
    fern docs dev
    ```

    库文档显示为一个导航部分，包含您库中每个模块、类、函数和类型的页面。
  </Step>

  <Step title="发布">
    发布您的库文档：

    ```bash
    fern generate --docs
    ```
  </Step>
</Steps>

<Accordion title="多库示例">
  您可以在同一个 `docs.yml` 中定义和引用多个库：

  ```yaml docs.yml
  libraries:
    plant-python-sdk:
      input:
        git: https://github.com/acme/plant-sdk-python
      output:
        path: ./static/python-docs
      lang: python
    plant-core:
      input:
        git: https://github.com/acme/plant-core-cpp
      output:
        path: ./static/cpp-docs
      lang: cpp

  navigation:
    - section: Python SDK 参考
      contents:
        - folder: ./static/python-docs
    - section: C++ API 参考
      contents:
        - folder: ./static/cpp-docs
  ```
</Accordion>

## 自定义生成的文档（可选）

您可以重新组织输出目录以重构侧边栏导航。移动、重命名或嵌套文件和子文件夹，Fern 会在下次 `fern docs dev` 或发布时获取新的布局。

例如，将 `./static/plant-sdk-docs` 拆分为 `getting-started/` 和 `reference/` 子文件夹会产生两个侧边栏部分：

```yaml docs.yml {4,6}
navigation:
  - section: Plant SDK 参考
    contents:
      - folder: ./static/plant-sdk-docs/getting-started
        title: 快速入门
      - folder: ./static/plant-sdk-docs/reference
        title: API 参考
```

您还可以通过直接修改 MDX 文件来编辑页面内容——生成的页面是[标准 MDX](/learn/docs/writing-content/markdown-basics)，因此您可以添加散文、示例、标注或任何[组件](/learn/docs/writing-content/components/overview)。重新运行 `fern docs md generate` 会覆盖 `output.path` 中的所有内容，因此请先提交您的自定义内容，如果您计划重新生成，请将手动编辑的页面保存在输出目录之外。

## 配置参考

<ParamField path="input.git" type="string" required={true}>
  包含库源代码的仓库的 GitHub URL。
</ParamField>

<ParamField path="input.subpath" type="string">
  仓库中库源代码的路径。对 monorepo 很有用。
</ParamField>

<ParamField path="output.path" type="string" required={true}>
  生成的 MDX 文件的写入目录，相对于 `fern/` 目录。
</ParamField>

<ParamField path="lang" type="string" required={true}>
  库的语言。支持的值：`python`、`cpp`。
</ParamField>

<ParamField path="config.doxyfile" type="string">
  自定义 Doxyfile 的路径。仅限 C++。
</ParamField>