Skip to content

Commit d1ca0fe

Browse files
i18n(zh-cn): Update astro-content.mdx (#11536)
Co-authored-by: Yan <[email protected]>
1 parent d965a79 commit d1ca0fe

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/content/docs/zh-cn/reference/modules/astro-content.mdx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const collections = { blog };
6767

6868
`loader` 是一个对象或函数,允许你从任何源加载数据到内容集合中,无论是本地还是远程数据。
6969

70-
更多有关示例请 [参考 `内容集合`指南](/zh-cn/guides/content-collections/#定义集合-loader)
70+
更多有关示例请 [参考`内容集合`指南](/zh-cn/guides/content-collections/#定义集合-loader)
7171

7272
#### `schema`
7373

@@ -79,7 +79,7 @@ export const collections = { blog };
7979

8080
`schema` 是一个可选的 Zod 对象,用于配置集合的文档 frontmatter 的类型和形状。每个值必须使用 [Zod 验证器](https://github.com/colinhacks/zod)
8181

82-
更多有关示例请 [参考 `内容集合`指南](/zh-cn/guides/content-collections/#定义集合模式schema)
82+
更多有关示例请 [参考`内容集合`指南](/zh-cn/guides/content-collections/#定义集合模式schema)
8383

8484
### `reference()`
8585

@@ -89,9 +89,9 @@ export const collections = { blog };
8989
<Since v="2.5.0" />
9090
</p>
9191

92-
在内容配置中使用 `reference()` 函数来定义从一个集合到另一个集合的关系或 "引用"。该函数接受一个集合名称,并在将引用转换为包含集合名称和引用 id 的对象之前,验证内容 `frontmatter` 或数据文件中指定的条目标识符
92+
内容配置中的 `reference()` 函数,用于定义一个集合与另一个集合之间的关联,或者说“引用”。该函数接受一个集合名称,并将其转换为一个包含集合名称与引用 id 的对象
9393

94-
此示例定义了从博客作者到 "作者 "集合的引用,以及到同一 "博客 "集合的相关文章数组的引用:
94+
此示例定义了从博客作者到 `authors` 集合的引用,以及到同一 `blog` 集合的相关文章数组的引用:
9595

9696
```ts
9797
import { defineCollection, reference, z } from 'astro:content';
@@ -100,9 +100,9 @@ import { glob, file } from 'astro/loaders';
100100
const blog = defineCollection({
101101
loader: glob({ pattern: '**/*.md', base: './src/data/blog' }),
102102
schema: z.object({
103-
// 通过 "id "从 "作者 "集合中引用单个作者
103+
// 通过 `id` 从 `authors` 集合中,引用单个作者
104104
author: reference('authors'),
105-
// 按 "slug "从 "blog "集合中引用相关帖子数组
105+
// 通过 `slug` 从 `blog` 集合中,引用相关帖子数组
106106
relatedPosts: z.array(reference('blog')),
107107
})
108108
});
@@ -115,7 +115,14 @@ const authors = defineCollection({
115115
export const collections = { blog, authors };
116116
```
117117

118-
更多有关示例请 [参考 `内容集合`指南](/zh-cn/guides/content-collections/#定义集合引用)
118+
在使用 `getEntry()``getEntries()` 的运行时环境下,对引用条目的有效性进行验证:
119+
120+
```astro title="src/pages/[posts].astro"
121+
// 如果引用条目是无效的,那么将会返回 undefined。
122+
const relatedPosts = await getEntries(blogPost.data.relatedPosts);
123+
```
124+
125+
更多有关示例请 [参考`内容集合`指南](/zh-cn/guides/content-collections/#定义集合引用)
119126

120127
### `getCollection()`
121128

@@ -143,7 +150,7 @@ const draftBlogPosts = await getCollection('blog', ({ data }) => {
143150
---
144151
```
145152

146-
更多有关示例请 [参考 `内容集合`指南](/zh-cn/guides/content-collections/#查询集合)
153+
更多有关示例请 [参考`内容集合`指南](/zh-cn/guides/content-collections/#查询集合)
147154

148155
### `getEntry()`
149156

@@ -252,8 +259,7 @@ import type { CollectionEntry } from 'astro:content';
252259

253260
#### `id`
254261

255-
**适用于:** `type: 'content'``type: 'data'` 集合
256-
**示例类型:** `'author-1' | 'author-2' | ...`
262+
**类型:** `string`
257263

258264
一个唯一的 ID。请注意,Astro 的内置 `glob()` 加载器中的所有 ID 都是 slug 化的。
259265

0 commit comments

Comments
 (0)