Skip to content
Merged
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
50 changes: 50 additions & 0 deletions src/content/docs/zh-cn/reference/legacy-flags.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: 旧版标志
i18nReady: true
---

为了帮助部分用户在 Astro 版本之间迁移,我们会偶尔引入一些 `legacy` 标志。

这些标志允许你在最新版本中可选地使用 Astro 的一些已弃用或过时的行为,以便你可以继续升级并享受 Astro 的新版本,直到你能够完全更新你的项目代码。

import Since from '~/components/Since.astro'

## 集合

<p>

**类型:** `boolean`<br />
**默认值:** `false`<br />
<Since v="5.0.0" />
</p>

启用内容集合的旧版行为(如 Astro v2 至 v4 中所使用)

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
legacy: {
collections: true
}
});
```

如果启用,(仅)`data` 和 `content` 集合会使用旧版的内容集合来实现。(仅)装载了 `loader` 的集合则会继续使用 Content Layer API 来实现。这两种类型的集合能同时存在于一个项目当中,而分别使用他们各自的实现形式。

以下限制仍然存在:

- 任何旧版(`type: 'content'` 或 `type: 'data'`)集合仍需位于 `src/content/` 目录下。
- 这些旧版集合不会被转换为隐式使用 `glob()` 加载器,而是由旧版代码处理。
- 在 `src/content/` 中禁止使用(定义了 `loader` 的)Content Layer API 集合,但它可以位于项目中任何其他的位置。

当你准备移除此标志,并为旧版集合迁移到新的 Content Layer API 时,你必须为 `src/content/` 中,那些想继续用作集合的目录去定义一个集合。声明一个空集合就足够了,Astro 将为你的旧版集合隐式地生成合适的定义:

```js
// src/content/config.ts
import { defineCollection, z } from 'astro:content';

const blog = defineCollection({ })

export const collections = { blog };
```
Loading