> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/reusable-content.md).

# 可重复使用的内容

创建可在各分区中重复使用的内容块，并在你更改某个实例时一次性更新所有使用处

可复用内容可让你在多个页面和章节之间同步内容，这样你就能同时编辑该区块的所有实例。

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-91ee7221fa85ca607bb05c425da8f3fe94812ae2%2F25_12_10_creating_content_reusable_content%402x.png?alt=media" alt="A GitBook screenshot showing reusable content"><figcaption><p>在某个章节内创建可复用内容。</p></figcaption></figure>

## 基础知识

可复用内容的工作方式与其他内容完全相同——你可以通过变更请求修改它，将其纳入审核工作流，并且它会在任何已发布的网站上正确呈现。

虽然可在多个分区中引用可复用内容，但它只属于一个 *父级分区*.

### “父章节”概念

父章节是拥有该可复用内容的章节。只有在这里才能编辑这些内容。

即使对可复用内容的更新会立即出现在所有实例中，所有更改也必须始于父章节——无论是直接编辑还是通过变更请求。

章节同时支持编辑工作流和安全性。由于 GitBook 采用基于权限的编辑，可复用内容只能从其父章节中更改。这确保了即使内容在整个组织中被复用，编辑权限也会得到尊重。

### 已知限制

#### 集成

集成提供的区块不支持用于可复用内容。这是因为 GitBook 中的集成是按章节安装的，而限制访问可确保第三方集成只拥有你授予的权限。在章节之间引用可复用内容会打破这一安全边界。

#### 搜索

目前，可复用内容只会出现在其父章节内的搜索结果中。我们正在积极努力消除这一限制，以便可复用内容在其被引用的任何位置都能出现在搜索结果中。

## 在应用中

### **创建可复用内容**

要创建可复用内容，请选择一个或多个块，然后打开 **“操作”菜单** <picture><source srcset="broken://files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-aabbca522107ef561981bdfe5af94605b31e0920%2F25_01_10_actions_icon_light.svg?alt=media" alt="The Actions menu icon in GitBook"></picture> ，选择 **转换为**，然后选择 **可复用内容**。你还可以为块命名，以便日后更轻松地查找和复用。

或者，选择一个或多个块，然后按 **Cmd + C** ，此时会弹出提示，询问你是否要创建可复用内容。

### **插入可复用内容**

插入可复用内容的方式与插入其他块相同。在空行处按 `/` 即可打开 **“插入”面板**。你也可以点击任意块或空行旁边的 `+` 。

页面侧边栏中的可复用内容面板会列出当前章节中先前创建的内容区块。

要插入当前章节或其他章节中的可复用内容，你可以访问：

1. 从 **“插入”面板** 或 `+` 菜单打开可复用内容选择器。
2. 使用顶部的章节选择器选择源章节。
3. 按名称搜索可复用区块，然后选择它进行插入。

从另一个章节插入内容不会转移所有权。只有父章节可以编辑可复用内容。来自该父章节的更新会继续同步到每个实例。

### **编辑可复用内容**

可复用内容就像其他内容一样——如果启用了实时编辑，你可以直接编辑任何实例；如果没有启用，则可通过变更请求编辑。你所做的任何更改都会同步到使用该内容的所有位置。

如果你是在变更请求中进行修改，那么一旦该变更请求合并，内容就会同步到所有其他实例。

### **分离可复用内容**

你可以打开 **“操作”菜单** <picture><source srcset="broken://files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-aabbca522107ef561981bdfe5af94605b31e0920%2F25_01_10_actions_icon_light.svg?alt=media" alt="The Actions menu icon in GitBook"></picture> 并选择 **分离**，将可复用内容分离。分离后，内容会转换回普通块。

一旦分离，你对该区块（或多个区块）所做的任何更改都不会反映到其他实例中，而你在那些实例中所做的更改也不会反映到已分离的区块中。可复用内容的所有其他实例仍会彼此同步。

### 删除可复用内容

如果需要，你可以从分区中彻底删除可复用内容。在页面目录中找到该内容，然后打开要删除内容旁边的 **“操作”菜单** <picture><source srcset="broken://files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-aabbca522107ef561981bdfe5af94605b31e0920%2F25_01_10_actions_icon_light.svg?alt=media" alt="The Actions menu icon in GitBook"></picture> ，并选择 **删除**.

删除可复用内容会将其 **从所有使用该内容的页面中删除**。此操作无法撤销。

## 与 GitHub 和 GitLab 同步

同步到 GitHub 和 GitLab 时，完全支持可复用内容。可复用内容将导出到专用的 `includes` 文件夹中，每个内容块单独保存为一个 Markdown 文件。

随后，你可以在其他页面中使用 `includes` 指令引用这些内容。

{% hint style="info" %}
同步时，会在每个已同步分区的根目录中创建 `.gitbook/includes` 目录（该目录可能并非整个代码库的根目录）。如果你的 `.gitbook/includes` 文件夹或其中的文件出现在分区目录中，你可能需要手动将它们从目录中隐藏。
{% endhint %}

#### 示例

{% hint style="success" %}
如果你是在 GitHub 端编写，请确保 include 的路径是相对于包含该引用的文件的路径（而不是仓库根目录）。
{% endhint %}

```markdown
{% include "../../.gitbook/includes/reusable-block.md" %}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/reusable-content.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
