内容类型构建器
🌐 Content-type Builder
Page summary:内容类型构建器是用于设计内容类型和组件的工具。本指南概述了内容类型构建器,并涵盖字段选项、关联关系、组件使用,以及分享数据建模技巧。
在 内容类型构建器中,用户可以创建和编辑他们的内容类型,该构建器可通过管理面板的主导航访问。
概览
🌐 Overview
The 内容类型构建器允许创建和管理内容类型,这些内容类型可以是:
- 集合类型:可以管理多个条目的内容类型。
- 单一类型:只能管理一个条目的内容类型。
- 组件:可用于多种集合类型和单一类型的内容结构。尽管它们从技术上讲不是正真的内容类型,因为它们不能独立存在,但组件也是通过内容类型构建器创建和管理的,与集合类型和单一类型的方式相同。
所有三者都显示为 内容类型构建器子导航中的类别。在每个类别中列出了所有已创建的内容类型和组件。
集合类型和单一类型也可以分组到文件夹,以便在项目增长时保持子导航的整洁。
🌐 Collection types and single types can also be grouped into folders, to keep the sub navigation organized as a project grows.
点击 内容类型构建器子导航中的搜索图标 以查找特定的集合类型、单一类型或组件。
在内容类型构建器的子导航中,还显示了一个集中式的 保存 按钮,适用于所有内容类型和组件。随着内容类型/组件和字段状态的显示,这使你可以同时处理多个内容类型和组件。可以显示 以下状态:
🌐 In the Content-type Builder's sub navigation is also displayed a centralised Save button that applies for all content-types and components. Along with the display of statuses for both content-types/components and fields, this allows you to work on several content-types and components at the same time. The following statuses can be displayed:
New或N表示某个内容类型/组件或字段是新的,尚未保存,Modified或M表示自上次保存以来内容类型/组件或字段已被修改,Deleted或D表示某个内容类型/组件或字段已被删除,但只有在保存后才会得到确认。
点击 保存 按钮旁边的 … 按钮可以访问其他选项,例如 撤销/重做上一次更改 和 放弃所有更改。这些选项也是集中化的,这意味着它们适用于自上次保存以来在所有内容类型、组件和字段上所做的最后操作。
🌐 Clicking on the ... button next to Save gives access to other options, such as Undo/Redo last change and Discard all changes. These options are also centralised, meaning that they apply to the last action(s) that was/were done on all content-types, components and fields since the last time you saved.
配置
🌐 Configuration
内容类型构建器使用起来无需配置。不过,用于组织内容类型的文件夹会存储在一个专门的文件中,可以直接编辑。
🌐 The Content-type Builder requires no configuration to be used. The folders used to organize content-types are however stored in a dedicated file, which can be edited directly.
基于代码的配置
🌐 Code-based configuration
在内容类型构建器子导航中显示的文件夹(见 使用文件夹组织内容类型)存储在 src/content-structure/groups.json 文件中。
🌐 The folders displayed in the Content-type Builder sub navigation (see Organizing content-types with folders) are stored in the src/content-structure/groups.json file.
这个文件会随着你项目的其余部分进行版本控制,所以本地定义的组织结构会与团队共享,并随你的应用部署。
🌐 The file is versioned with the rest of your project, so the organization defined locally is shared with your team and deployed with your application.
因此,文件夹的组织会跟随你的项目代码:部署文件可以把它从一个环境移到另一个环境。
🌐 Folder organization therefore travels with your project's code: deploy the file to move it from one environment to another.
数据传输 导出、导入和传输数据库内容和媒体,而不是项目源文件,所以它从不包含 groups.json。传输完成后,目标项目会保留其自身 groups.json 中定义的文件夹。要在两边都拥有相同的文件夹,请部署带有你代码的文件。
文件中的文件夹被称为 groups,并按章节列出,即 collectionTypes 和 singleTypes。每个组都有一个标识符、名称、父级和子级列表:
🌐 Folders are called groups in the file, and are listed per section, collectionTypes and singleTypes. Each group has an identifier, a name, a parent, and a list of children:
{
"version": 1,
"sections": {
"collectionTypes": {
"groups": [
{
"id": "grp_x8k2m4p7q1",
"name": "Restaurants",
"parent": null,
"children": [{ "type": "group", "id": "grp_c3v9n5t2w6" }]
},
{
"id": "grp_c3v9n5t2w6",
"name": "Menus",
"parent": "grp_x8k2m4p7q1",
"children": [{ "type": "contentType", "uid": "api::menu.menu" }]
}
]
},
"singleTypes": {
"groups": []
}
}
}
以下属性可用:
🌐 The following properties are available:
| 属性 | 描述 |
|---|---|
version | 文件格式的版本。唯一支持的值是 1。 |
id | 文件夹的标识符:任何非空字符串,在两个部分中必须唯一。内容类型构建器会生成以 grp_ 为前缀的标识符,手写的标识符如 products 也是有效的。 |
name | 文件夹名称,长度为 1 到 255 个字符,不能有前后空格。共享同一父文件夹的两个文件夹名称必须不同,不论大小写。 |
parent | 父文件夹的标识符,或者对于位于其部分根目录的文件夹使用 null。 |
children | 文件夹包含的内容类型和子文件夹的有序列表。内容类型通过其 uid 引用,文件夹通过其 id 引用。 |
文件夹最多可以嵌套三层,而且一个内容类型只能属于一个文件夹。
🌐 Folders can be nested up to 3 levels deep, and a content-type can only belong to one folder.
手动编辑文件:Strapi 会读取什么,以及它如何处理无效文件
在构建时,文件会被编译成 dist/src/content-structure/groups.json,这个编译好的版本就是 Strapi 启动服务器时读取的。