Skip to content

遗留标志

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

¥To help some users migrate between versions of Astro, we occasionally introduce legacy flags.

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

¥These flags allow you to opt in to some deprecated or otherwise outdated behavior of Astro in the latest version, so that you can continue to upgrade and take advantage of new Astro releases until you are able to fully update your project code.

¥Collections

类型:boolean
默认:false

¥Type: boolean
Default: false

Added in: astro@5.0.0

为内容集合启用旧行为(如在 Astro v2 到 v4 中使用)

¥Enable legacy behavior for content collections (as used in Astro v2 through v4)

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

如果启用,datacontent 集合(仅)使用旧内容集合实现进行处理。仅具有 loader 的集合将继续使用内容层 API。两种集合可能存在于同一个项目中,每种集合都使用各自的实现。

¥If enabled, data and content collections (only) are handled using the legacy content collections implementation. Collections with a loader (only) will continue to use the Content Layer API instead. Both kinds of collections may exist in the same project, each using their respective implementations.

以下限制仍然存在:

¥The following limitations continue to exist:

  • 任何旧版(type: 'content'type: 'data')集合都必须继续位于 src/content/ 目录中。

  • 这些旧集合将不会被转换为隐式使用 glob() 加载器,而将由旧代码处理。

  • 使用内容层 API(定义了 loader)的集合在 src/content/ 中是被禁止的,但可能存在于你项目中的任何其他位置。

当你准备删除此标志并迁移到旧版集合的新内容层 API 时,你必须为 src/content/ 中要继续用作集合的任何目录定义一个集合。声明一个空集合就足够了,Astro 将隐式生成适合你的旧集合的适当定义:

¥When you are ready to remove this flag and migrate to the new Content Layer API for your legacy collections, you must define a collection for any directories in src/content/ that you want to continue to use as a collection. It is sufficient to declare an empty collection, and Astro will implicitly generate an appropriate definition for your legacy collections:

src/content/config.ts
import { defineCollection, z } from 'astro:content';
const blog = defineCollection({ })
export const collections = { blog };
Astro 中文网 - 粤ICP备13048890号