Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n(zh-cn): update content-collections.mdx #8995

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Changes from 2 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
31 changes: 31 additions & 0 deletions src/content/docs/zh-cn/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,37 @@ const { Content } = await entry.render();

请参考我们的[手把手教程](/zh-cn/tutorials/add-content-collections/)中的示例,了解如何将位于 `src/pages/posts/` 的基本博客示例转换为 `src/content/posts` 目录下的示例。该教程使用了[构建博客教程的完整项目](https://github.com/withastro/blog-tutorial-demo)的代码库。

## 启用 JSON Schema 生成

<p><Since v="4.13.0" /></p>

如果你正在处理 `data` 的类型集合,Astro 将为你的编辑器生成 JSON schema 文件,以获取智能提示和类型检查。这使用了一个名为 [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema#known-issues) 的库,基于你在 `src/content/config.ts` 中定义的集合生成项目中每个数据集合的单独文件。

此功能要求你手动将 schema 的文件路径设置为集合中每个数据条目文件的 `$schema` 值:

```json title="src/content/authors/armand.json" ins={2}
{
"$schema": "../../../.astro/collections/authors.schema.json",
"name": "Armand",
"skills": ["Astro", "Starlight"]
}
```

或者,你可以在编辑器设置中设置这个值。例如,要在 [VSCode 的 `json.schemas` 设置](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings)中设置这个值,请提供要匹配的文件路径和你的 JSON schema 的位置:

```json
{
"json.schemas": [
{
"fileMatch": [
"/src/content/authors/**"
],
"url": "./.astro/collections/authors.schema.json"
}
]
}
```

## 启用构建缓存

<p><Since v="3.5.0" /><Badge class="neutral-badge" text="实验性" /></p>
Expand Down
Loading