Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/content/docs/zh-cn/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ relatedPosts:

### 定义自定义 slugs

当使用 `type: 'content'` 时,每个内容条目从它的[文件 `id`](/zh-cn/reference/api-reference/#id) 生成一个 URL 友好的 `slug` 属性。slug 用于直接从集合中查询条目。在根据内容创建新页面和 URL 时,它也很有用。
当使用 `type: 'content'` 时,每个内容条目从它的[文件 `id`](/zh-cn/reference/modules/astro-content/#id) 生成一个 URL 友好的 `slug` 属性。slug 用于直接从集合中查询条目。在根据内容创建新页面和 URL 时,它也很有用。

你可以通过将自己的 `slug` 属性添加到文件 frontmatter 来覆盖条目生成的 slug。这类似于其他 Web 框架的 "permalink" 特性。`"slug"` 是一个特殊的保留属性名称,不允许出现在自定义集合 `schema` 中,也不会出现在条目的 `data` 属性中。

Expand All @@ -325,7 +325,7 @@ slug: my-custom-slug/supports/slashes

## 查询集合

Astro 提供了两个函数来查询一个集合并返回一个(或多个)内容条目:[`getCollection()`](/zh-cn/reference/api-reference/#getcollection) 和 [`getEntry()`](/zh-cn/reference/api-reference/#getentry)。
Astro 提供了两个函数来查询一个集合并返回一个(或多个)内容条目:[`getCollection()`](/zh-cn/reference/modules/astro-content/#getcollection) 和 [`getEntry()`](/zh-cn/reference/modules/astro-content/#getentry)。

```js
import { getCollection, getEntry } from 'astro:content';
Expand All @@ -342,7 +342,7 @@ const allBlogPosts = await getCollection('blog');
const graceHopperProfile = await getEntry('authors', 'grace-hopper');
```

这两个函数都返回由 [`CollectionEntry`](/zh-cn/reference/api-reference/#集合条目类型) 类型定义的内容条目。
这两个函数都返回由 [`CollectionEntry`](/zh-cn/reference/modules/astro-content/#collectionentry) 类型定义的内容条目。

### 使用引用的数据

Expand Down Expand Up @@ -437,7 +437,7 @@ const blogEntries = await getCollection('blog');

组件还可以将整个内容条目作为属性传递。

如果这样做,你可以使用 [`CollectionEntry`](/zh-cn/reference/api-reference/#集合条目类型) 实用工具使用 TypeScript 正确地输入组件属性。此实用工具接受与集合 schema 名称匹配的字符串参数,并将继承该集合 schema 的所有属性。
如果这样做,你可以使用 [`CollectionEntry`](/zh-cn/reference/modules/astro-content/#collectionentry) 实用工具使用 TypeScript 正确地输入组件属性。此实用工具接受与集合 schema 名称匹配的字符串参数,并将继承该集合 schema 的所有属性。

```astro /CollectionEntry(?:<.+>)?/
---
Expand Down Expand Up @@ -507,7 +507,7 @@ const { Content } = await entry.render();

### 构建为服务器输出(SSR)

如果你正在构建一个动态网站(使用 Astro 的 SSR 支持),则不需要在构建期间提前生成任何路径。相反,你的页面应该检查请求(使用 `Astro.request` 或 `Astro.params`)以按需找到 `slug`,然后使用 [`getEntry()`](/zh-cn/reference/api-reference/#getentry) 获取它。
如果你正在构建一个动态网站(使用 Astro 的 SSR 支持),则不需要在构建期间提前生成任何路径。相反,你的页面应该检查请求(使用 `Astro.request` 或 `Astro.params`)以按需找到 `slug`,然后使用 [`getEntry()`](/zh-cn/reference/modules/astro-content/#getentry) 获取它。


```astro
Expand Down
4 changes: 1 addition & 3 deletions src/content/docs/zh-cn/guides/imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ glob 模式是一个支持特殊通配符的文件路径。用于一次引用项

#### `Astro.glob()` vs `getCollection()`

[内容集合](/zh-cn/guides/content-collections/) 提供用于加载多个文件的 [`getCollection()` API](/zh-cn/reference/api-reference/#getcollection) 代替 `Astro.glob()`。如果你的内容文件 (例如 Markdown, MDX, Markdoc) 位于`src/content/` 目录内的集合中,使用 `getCollection()` [查询集合](/zh-cn/guides/content-collections/#查询集合)并返回内容条目。


[内容集合](/zh-cn/guides/content-collections/) 提供用于加载多个文件的 [`getCollection()` API](/zh-cn/reference/modules/astro-content/#getcollection) 代替 `Astro.glob()`。如果你的内容文件 (例如 Markdown, MDX, Markdoc) 位于`src/content/` 目录内的集合中,使用 `getCollection()` [查询集合](/zh-cn/guides/content-collections/#查询集合)并返回内容条目。

## WASM

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/zh-cn/guides/markdown-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const posts = Object.values(await import.meta.glob('../posts/*.md', { eager: tru

当通过辅助函数从集合中获取数据时,Markdown 的 frontmatter 属性在 `data` 对象(例如 `post.data.title`)上可用。此外,`body` 包含了 Markdown 的正文内容,这部分内容是原始的、未编译的字符串类型。

<ReadMore>请参阅完整的 [集合条目类型](/zh-cn/reference/api-reference/#集合条目类型)。</ReadMore>
<ReadMore>请参阅完整的 [集合条目类型](/zh-cn/reference/modules/astro-content/#collectionentry)。</ReadMore>

#### 导入 Markdown

Expand Down
Loading