diff --git a/src/content/docs/de/tutorial/6-islands/4.mdx b/src/content/docs/de/tutorial/6-islands/4.mdx index cd7c4fc0c4767..6ceab133973e6 100644 --- a/src/content/docs/de/tutorial/6-islands/4.mdx +++ b/src/content/docs/de/tutorial/6-islands/4.mdx @@ -119,7 +119,8 @@ Aktualisiere Astro und alle Integrationen auf die neuesten Versionen, indem du i ```ts title="src/content.config.ts" import { glob } from "astro/loaders"; - import { z, defineCollection } from "astro:content"; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/en/guides/actions.mdx b/src/content/docs/en/guides/actions.mdx index fa2bec9393f5b..9a5c00ff1d26c 100644 --- a/src/content/docs/en/guides/actions.mdx +++ b/src/content/docs/en/guides/actions.mdx @@ -24,7 +24,7 @@ Actions are defined in a `server` object exported from `src/actions/index.ts`: ```ts title="src/actions/index.ts" import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { myAction: defineAction({ /* ... */ }) @@ -62,11 +62,11 @@ Follow these steps to define an action and call it in a `script` tag in your Ast } ``` -2. Import the `defineAction()` utility from `astro:actions`, and the `z` object from `astro:schema`. +2. Import the `defineAction()` utility from `astro:actions`, and the `z` object from `astro/zod`. ```ts ins={1-2} title="src/actions/index.ts" import { defineAction } from 'astro:actions'; - import { z } from 'astro:schema'; + import { z } from 'astro/zod'; export const server = { // action declarations @@ -77,7 +77,7 @@ Follow these steps to define an action and call it in a `script` tag in your Ast ```ts ins={5-12} title="src/actions/index.ts" import { defineAction } from 'astro:actions'; - import { z } from 'astro:schema'; + import { z } from 'astro/zod'; export const server = { getGreeting: defineAction({ @@ -213,7 +213,7 @@ This example throws an error from a `likePost` action when a user is not logged ```ts title="src/actions/index.ts" ins=/ActionError(?= )/ ins={9-12} import { defineAction, ActionError } from "astro:actions"; -import { z } from "astro:schema"; +import { z } from "astro/zod"; export const server = { likePost: defineAction({ @@ -290,7 +290,7 @@ Actions accept JSON data by default. To accept form data from an HTML form, set ```ts title="src/actions/index.ts" ins={6} import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { comment: defineAction({ @@ -319,7 +319,7 @@ To apply a union of different validators, use the `z.discriminatedUnion()` wrapp ```ts title="src/actions/index.ts" {7-21} "create" "update" import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { changeUser: defineAction({ @@ -378,7 +378,7 @@ The following example shows a validated newsletter registration form that accept ```ts title="src/actions/index.ts" ins={5-12} import { defineAction } from 'astro:actions'; - import { z } from 'astro:schema'; + import { z } from 'astro/zod'; export const server = { newsletter: defineAction({ @@ -492,7 +492,7 @@ For example, say you have a `createProduct` action that returns the generated pr ```ts title="src/actions/index.ts" mark={10} import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { createProduct: defineAction({ diff --git a/src/content/docs/en/guides/astro-db.mdx b/src/content/docs/en/guides/astro-db.mdx index 647a37c77d53d..c2642ec763152 100644 --- a/src/content/docs/en/guides/astro-db.mdx +++ b/src/content/docs/en/guides/astro-db.mdx @@ -401,7 +401,7 @@ You can also use [Astro actions](/en/guides/actions/) to insert data into an Ast // src/actions/index.ts import { db, Comment } from 'astro:db'; import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { addComment: defineAction({ diff --git a/src/content/docs/en/guides/content-collections.mdx b/src/content/docs/en/guides/content-collections.mdx index 134911f2daccd..5dee94f1a4629 100644 --- a/src/content/docs/en/guides/content-collections.mdx +++ b/src/content/docs/en/guides/content-collections.mdx @@ -132,8 +132,9 @@ Each individual collection configures: - [a build-time `schema`](#defining-the-collection-schema) for type safety (optional, but highly recommended!) ```ts title="src/content.config.ts" -// 1. Import utilities from `astro:content` -import { defineCollection, z } from 'astro:content'; +// 1. Import utilities from `astro:content` and `astro/zod` +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; // 2. Import loader(s) import { glob } from 'astro/loaders'; @@ -332,7 +333,8 @@ In order for Astro to recognize a new or updated schema, you may need to restart Providing a `schema` is optional, but highly recommended! If you choose to use a schema, then every frontmatter or data property of your collection entries must be defined using a [Zod data type](#defining-datatypes-with-zod): ```ts title="src/content.config.ts" {6-11,15-19} -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; import { glob, file } from 'astro/loaders'; const blog = defineCollection({ @@ -360,11 +362,12 @@ export const collections = { blog, dogs }; Astro uses [Zod](https://github.com/colinhacks/zod) to power its content schemas. With Zod, Astro is able to validate every file's data within a collection *and* provide automatic TypeScript types when you query content from inside your project. -To use Zod in Astro, import the `z` utility from `"astro:content"`. This is a re-export of the Zod library, and it supports all of the features of Zod 3. +To use Zod in Astro, import the `z` utility from `"astro/zod"`. This is a re-export of the Zod library, and it supports all of the features of Zod 3. ```ts // Example: A cheatsheet of many common Zod datatypes -import { z, defineCollection } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; defineCollection({ schema: z.object({ @@ -405,7 +408,8 @@ With the [`reference()` function](/en/reference/modules/astro-content/#reference A common example is a blog post that references reusable author profiles stored as JSON, or related post URLs stored in the same collection: ```ts title="src/content.config.ts" -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from 'astro:content'; +import { z } from 'astro/zod'; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/en/guides/images.mdx b/src/content/docs/en/guides/images.mdx index 91fbbbec33997..fa38b308a1ecb 100644 --- a/src/content/docs/en/guides/images.mdx +++ b/src/content/docs/en/guides/images.mdx @@ -590,7 +590,8 @@ This is a blog post The `image` helper for the content collections schema lets you validate and import the image. ```ts title="src/content.config.ts" -import { defineCollection, z } from "astro:content"; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; const blogCollection = defineCollection({ schema: ({ image }) => z.object({ diff --git a/src/content/docs/en/guides/integrations-guide/mdx.mdx b/src/content/docs/en/guides/integrations-guide/mdx.mdx index d821fc92967cd..3ad1ea54487e7 100644 --- a/src/content/docs/en/guides/integrations-guide/mdx.mdx +++ b/src/content/docs/en/guides/integrations-guide/mdx.mdx @@ -101,7 +101,8 @@ It also adds extra features to standard MDX, including support for Markdown-styl To include your local MDX files in a content collection, make sure that your [collection loader](/en/guides/content-collections/#build-time-collection-loaders) is configured to load content from `.mdx` files: ```js title="src/content.config.ts" ins="mdx" -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/en/guides/integrations-guide/react.mdx b/src/content/docs/en/guides/integrations-guide/react.mdx index 45b238fbbcd1a..6a0c70ddfc4f7 100644 --- a/src/content/docs/en/guides/integrations-guide/react.mdx +++ b/src/content/docs/en/guides/integrations-guide/react.mdx @@ -167,7 +167,7 @@ The example below gets the current value of likes from a counter, typed as a num ```ts title="actions.ts" ins={3,11} import { defineAction, type SafeResult } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; import { getActionState } from '@astrojs/react/actions'; export const server = { diff --git a/src/content/docs/en/guides/sessions.mdx b/src/content/docs/en/guides/sessions.mdx index bde6ae485f064..7f2d333af26a3 100644 --- a/src/content/docs/en/guides/sessions.mdx +++ b/src/content/docs/en/guides/sessions.mdx @@ -90,7 +90,7 @@ In actions, the session object is available on the `context` object. For example ```ts title="src/actions/addToCart.ts" "context.session" import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { addToCart: defineAction({ diff --git a/src/content/docs/en/guides/upgrade-to/v6.mdx b/src/content/docs/en/guides/upgrade-to/v6.mdx index a4937752974d6..61a0aba3404fa 100644 --- a/src/content/docs/en/guides/upgrade-to/v6.mdx +++ b/src/content/docs/en/guides/upgrade-to/v6.mdx @@ -155,6 +155,31 @@ someLogic(build.assetsPrefix) Read more about the [`astro:config` virtual modules](/en/reference/modules/astro-config/). +### Deprecated: `astro:schema` and `z` from `astro:content` + + + +In Astro 5.x, `astro:schema` was introduced as an alias of `astro/zod`. `z` was also exported from `astro:content` for convenience. However this occasionally created confusion for users who were unsure about where they should be importing from. + +Astro 6.0 deprecates `astro:schema` and `z` from `astro:content` in favor of `astro/zod`. + +#### What should I do? + +Replace any occurrences of `astro:schema` with `astro/zod`: + +```ts del={1} ins={2} +import { z } from "astro:schema" +import { z } from "astro/zod" +``` + +Remove `z` from your `astro:content` imports and import `z` separately from `astro/zod` instead: + +```ts title="src/content.config.ts" del={1} ins={2-3} +import { defineCollection, z } from "astro:content" +import { defineCollection } from "astro:content" +import { z } from "astro/zod" +``` +See more about [defining collection schemas with Zod](/en/guides/content-collections/#defining-datatypes-with-zod). ## Removed The following features have now been entirely removed from the code base and can no longer be used. Some of these features may have continued to work in your project even after deprecation. Others may have silently had no effect. @@ -207,9 +232,10 @@ Rename and move this file to `src/content.config.ts` Import [Astro's built-in `glob()` loader](/en/guides/content-collections/#the-glob-loader) and define the `pattern` and `base` for your collection entries: -```ts ins={3,6} +```ts ins={4,7} // src/content.config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; import { glob } from 'astro/loaders'; const blog = defineCollection({ @@ -228,9 +254,10 @@ const blog = defineCollection({ a collection that defines a collection type (`type: 'content'` or `type: 'data'`) / ([`ContentCollectionInvalidTypeError`](/en/reference/errors/content-collection-invalid-type/)) There are no longer different types of collections. This must be deleted from your collection definition. -```ts del={7} +```ts del={8} // src/content.config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/en/recipes/i18n.mdx b/src/content/docs/en/recipes/i18n.mdx index 8e4f12cc7859f..6d7b702676795 100644 --- a/src/content/docs/en/recipes/i18n.mdx +++ b/src/content/docs/en/recipes/i18n.mdx @@ -87,7 +87,8 @@ If you prefer the default language to not be visible in the URL unlike other lan ```ts //src/content.config.ts - import { defineCollection, z } from 'astro:content'; + import { defineCollection } from 'astro:content'; + import { z } from 'astro/zod'; const blogCollection = defineCollection({ schema: z.object({ diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index b0e9e324ad9dc..c2220cee715f5 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -188,7 +188,7 @@ The following example shows a loader that fetches data from a provided feed URL ```ts title="src/feed-loader.ts" // 1. Import the `Loader` type and any other dependencies needed import type { Loader } from 'astro/loaders'; -import { z } from 'astro:content'; +import { z } from 'astro/zod'; import { loadFeedData } from "./feed.js"; // 2. Define any options that your loader needs diff --git a/src/content/docs/en/reference/modules/astro-actions.mdx b/src/content/docs/en/reference/modules/astro-actions.mdx index 7d85ab5af3a03..145cc883727d6 100644 --- a/src/content/docs/en/reference/modules/astro-actions.mdx +++ b/src/content/docs/en/reference/modules/astro-actions.mdx @@ -42,7 +42,7 @@ A utility to define new actions in the `src/actions/index.ts` file. This accepts ```ts title="src/actions/index.ts" import { defineAction } from 'astro:actions'; -import { z } from 'astro:schema'; +import { z } from 'astro/zod'; export const server = { getGreeting: defineAction({ diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx index 0062de74155e9..aa759c91757ec 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -24,7 +24,6 @@ For features and usage examples, [see our content collections guide](/en/guides/ ```js import { - z, defineCollection, defineLiveCollection, getCollection, @@ -48,7 +47,8 @@ import { A utility to configure a collection in a `src/content.config.*` file. ```ts title="src/content.config.ts" -import { z, defineCollection } from 'astro:content'; +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; import { glob } from 'astro/loaders'; const blog = defineCollection({ @@ -157,7 +157,8 @@ A function used in the content config to define a relationship, or "reference", This example defines references from a blog author to the `authors` collection and an array of related posts to the same `blog` collection: ```ts title="src/content.config.ts" -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from 'astro:content'; +import { z } from 'astro/zod'; import { glob, file } from 'astro/loaders'; const blog = defineCollection({ @@ -450,7 +451,8 @@ This includes the following property: - `image` - The `image()` schema helper that allows you [to use local images in Content Collections](/en/guides/images/#images-in-content-collections) ```ts title="src/content.config.ts" "SchemaContext" {4-8,12,15} -import { defineCollection, z, type SchemaContext } from "astro:content"; +import { defineCollection, type SchemaContext } from "astro:content"; +import { z } from 'astro/zod'; import { glob } from 'astro/loaders'; export const imageSchema = ({ image }: SchemaContext) => diff --git a/src/content/docs/en/tutorial/6-islands/4.mdx b/src/content/docs/en/tutorial/6-islands/4.mdx index 066162404180c..798030fe2374a 100644 --- a/src/content/docs/en/tutorial/6-islands/4.mdx +++ b/src/content/docs/en/tutorial/6-islands/4.mdx @@ -118,8 +118,9 @@ Upgrade to the latest version of Astro, and upgrade all integrations to their la ```ts title="src/content.config.ts" // Import the glob loader import { glob } from "astro/loaders"; - // Import utilities from `astro:content` - import { z, defineCollection } from "astro:content"; + // Import utilities from `astro:content` and `astro/zod` + import { defineCollection } from "astro:content"; + import { z } from 'astro/zod'; // Define a `loader` and `schema` for each collection const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/es/guides/images.mdx b/src/content/docs/es/guides/images.mdx index ca490618a5d20..6787d8ba93548 100644 --- a/src/content/docs/es/guides/images.mdx +++ b/src/content/docs/es/guides/images.mdx @@ -590,7 +590,8 @@ Contenido del post de blog. El helper `image` para el esquema de colecciones de contenido te permite validar e importar la imagen. ```ts title="src/content.config.ts" -import { defineCollection, z } from "astro:content"; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: ({ image }) => z.object({ diff --git a/src/content/docs/es/reference/legacy-flags.mdx b/src/content/docs/es/reference/legacy-flags.mdx index e810b9236c57f..8ca1fb4bfb98f 100644 --- a/src/content/docs/es/reference/legacy-flags.mdx +++ b/src/content/docs/es/reference/legacy-flags.mdx @@ -41,7 +41,8 @@ Cuando estés listo para eliminar este flag y migrar a la nueva API de Content L ```js // src/content/config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blog = defineCollection({ }) diff --git a/src/content/docs/es/tutorial/6-islands/4.mdx b/src/content/docs/es/tutorial/6-islands/4.mdx index 279534f12f7c3..96d3cf7b1befd 100644 --- a/src/content/docs/es/tutorial/6-islands/4.mdx +++ b/src/content/docs/es/tutorial/6-islands/4.mdx @@ -118,8 +118,9 @@ Actualiza a la última versión de Astro y actualiza todas las integraciones a s ```ts title="src/content.config.ts" // Importa el cargador glob import { glob } from "astro/loaders"; - // Importa utilidades de `astro:content` - import { z, defineCollection } from "astro:content"; + // Importa utilidades de `astro:content` y `astro/zod` + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // Define un `loader` y un `schema` para cada colección const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/fr/guides/content-collections.mdx b/src/content/docs/fr/guides/content-collections.mdx index a9b864fb54eec..3bc9dba16bee5 100644 --- a/src/content/docs/fr/guides/content-collections.mdx +++ b/src/content/docs/fr/guides/content-collections.mdx @@ -63,8 +63,9 @@ Les collections individuelles utilisent `defineCollection()` pour configurer : Pour définir des collections, vous devez créer un fichier `src/content.config.ts` dans votre projet (les extensions `.js` et `.mjs` sont également prises en charge). Il s'agit d'un fichier spécial qu'Astro utilisera pour configurer vos collections de contenu en fonction de la structure suivante : ```ts title="src/content.config.ts" -// 1. Importer des utilitaires depuis `astro:content` -import { defineCollection, z } from 'astro:content'; +// 1. Importer des utilitaires depuis `astro:content` et `astro/zod` +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; // 2. Importer un ou plusieurs chargeurs import { glob, file } from 'astro/loaders'; @@ -89,8 +90,9 @@ Le [chargeur `glob()`](/fr/reference/content-loader-reference/#le-chargeur-glob) Le [chargeur `file()`](/fr/reference/content-loader-reference/#le-chargeur-file) crée plusieurs entrées à partir d'un seul fichier local. Chaque entrée du fichier doit avoir un nom de propriété `id` unique. Il accepte un chemin de fichier `base` vers votre fichier et éventuellement une [fonction `parser`](#fonction-parser) pour les fichiers de données qu'il ne peut pas analyser automatiquement. Utilisez ce chargeur lorsque votre fichier de données peut être analysé comme un tableau d'objets. -```ts title="src/content.config.ts" {5,9} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {6,10} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; // Non disponible avec l'API héritée const blog = defineCollection({ @@ -210,8 +212,9 @@ Pour qu'Astro reconnaisse un schéma nouveau ou mis à jour, vous devrez peut-ê Chaque frontmatter ou propriété de données de vos entrées de collection doit être défini à l’aide d’un type de données Zod : -```ts title="src/content.config.ts" {6-11,15-19} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {7-12,16-20} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; // Non disponible avec l'API héritée const blog = defineCollection({ @@ -239,11 +242,12 @@ export const collections = { blog, dogs }; Astro utilise [Zod](https://github.com/colinhacks/zod) pour alimenter ses schémas de contenu. Avec Zod, Astro est capable de valider les données de chaque fichier au sein d'une collection *et* de fournir des types TypeScript automatiques lorsque vous interrogez le contenu à partir de votre projet. -Pour utiliser Zod dans Astro, importez l'utilitaire `z` depuis `"astro:content"`. Il s'agit d'une réexportation de la bibliothèque Zod, et elle prend en charge toutes les fonctionnalités de Zod. +Pour utiliser Zod dans Astro, importez l'utilitaire `z` depuis `"astro/zod"`. Il s'agit d'une réexportation de la bibliothèque Zod, et elle prend en charge toutes les fonctionnalités de Zod. ```ts // Exemple : une aide-mémoire de nombreux types de données Zod courants -import { z, defineCollection } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; defineCollection({ schema: z.object({ @@ -286,7 +290,8 @@ Avec la [fonction `reference()`](/fr/reference/modules/astro-content/#reference) Un exemple courant est un article de blog qui fait référence à des profils d'auteur réutilisables stockés au format JSON ou à des URL d'articles associés stockées dans la même collection : ```ts title="src/content.config.ts" -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/fr/guides/images.mdx b/src/content/docs/fr/guides/images.mdx index bf0c8fe30352c..99b9476a7a8b5 100644 --- a/src/content/docs/fr/guides/images.mdx +++ b/src/content/docs/fr/guides/images.mdx @@ -590,7 +590,8 @@ Ceci est un article de blog L'assistant `image` pour le schéma des collections de contenu vous permet de valider et d'importer l'image. ```ts title="src/content.config.ts" -import { defineCollection, z } from "astro:content"; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: ({ image }) => z.object({ diff --git a/src/content/docs/fr/guides/integrations-guide/mdx.mdx b/src/content/docs/fr/guides/integrations-guide/mdx.mdx index 8225525c8cd42..1610cde3a12e2 100644 --- a/src/content/docs/fr/guides/integrations-guide/mdx.mdx +++ b/src/content/docs/fr/guides/integrations-guide/mdx.mdx @@ -101,7 +101,8 @@ Les fichiers `.mdx` doivent être écrits en [syntaxe MDX](https://mdxjs.com/doc Pour inclure des fichiers MDX dans une collection de contenus, assurez-vous que votre [chargeur de collection](/fr/guides/content-collections/#définir-le-chargeur-de-collection-loader) est configuré pour charger du contenu à partir de fichiers `.mdx` : ```js title="src/content.config.ts" ins="mdx" -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/fr/recipes/i18n.mdx b/src/content/docs/fr/recipes/i18n.mdx index 74e0f6e997fa2..3231921fe03c6 100644 --- a/src/content/docs/fr/recipes/i18n.mdx +++ b/src/content/docs/fr/recipes/i18n.mdx @@ -87,7 +87,8 @@ Si vous préférez que la langue par défaut ne soit pas visible dans l'URL cont ```ts //src/content.config.ts - import { defineCollection, z } from 'astro:content'; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: z.object({ diff --git a/src/content/docs/fr/reference/content-loader-reference.mdx b/src/content/docs/fr/reference/content-loader-reference.mdx index 4f60e23b9e00c..9145e28e2956b 100644 --- a/src/content/docs/fr/reference/content-loader-reference.mdx +++ b/src/content/docs/fr/reference/content-loader-reference.mdx @@ -183,7 +183,7 @@ Le modèle recommandé consiste à définir une fonction qui accepte les options ```ts title=loader.ts import type { Loader, LoaderContext } from 'astro/loaders'; -import { z } from 'astro:content'; +import { z } from 'astro/zod'; import { loadFeedData } from "./feed.js"; // Définir toutes les options dont le chargeur a besoin @@ -209,8 +209,9 @@ export function myLoader(options: { url: string, apiKey: string }): Loader { Ces options de configuration peuvent ensuite être définies lors de la définition d'une collection : -```ts title="src/content.config.ts" {2,5-8} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {3,6-9} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import myLoader from '../../loader.ts'; const blog = defineCollection({ diff --git a/src/content/docs/fr/reference/legacy-flags.mdx b/src/content/docs/fr/reference/legacy-flags.mdx index f3ddc628b8a7a..269e44e63db75 100644 --- a/src/content/docs/fr/reference/legacy-flags.mdx +++ b/src/content/docs/fr/reference/legacy-flags.mdx @@ -42,7 +42,8 @@ Lorsque vous êtes prêt à supprimer cette option et à migrer vers la nouvelle ```js // src/content/config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blog = defineCollection({ }) diff --git a/src/content/docs/fr/reference/modules/astro-content.mdx b/src/content/docs/fr/reference/modules/astro-content.mdx index cbed7c46c1281..c72ab191c4222 100644 --- a/src/content/docs/fr/reference/modules/astro-content.mdx +++ b/src/content/docs/fr/reference/modules/astro-content.mdx @@ -18,7 +18,6 @@ Les collections de contenu proposent des API pour configurer et interroger vos d ```js import { - z, defineCollection, getCollection, getEntry, @@ -38,7 +37,8 @@ import { `defineCollection()` est un utilitaire pour configurer une collection dans un fichier `src/content.config.*`. ```ts title="src/content.config.ts" -import { z, defineCollection } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ @@ -94,7 +94,8 @@ La fonction `reference()` est utilisée dans la configuration du contenu pour d Cet exemple définit les références d'un auteur de blog à la collection `authors` et un tableau d'articles associés à la même collection `blog` : ```ts -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; const blog = defineCollection({ @@ -304,7 +305,8 @@ Il inclut la propriété suivante : - `image` - L'assistant de schéma `image()` qui vous permet [d'utiliser des images locales dans les collections de contenu](/fr/guides/images/#images-dans-les-collections-de-contenu) ```ts -import { defineCollection, z, type SchemaContext } from "astro:content"; +import { defineCollection, type SchemaContext } from "astro:content"; +import { z } from "astro/zod"; export const imageSchema = ({ image }: SchemaContext) => z.object({ diff --git a/src/content/docs/fr/tutorial/6-islands/4.mdx b/src/content/docs/fr/tutorial/6-islands/4.mdx index d62c42d5fa596..0a64f86292282 100644 --- a/src/content/docs/fr/tutorial/6-islands/4.mdx +++ b/src/content/docs/fr/tutorial/6-islands/4.mdx @@ -118,8 +118,9 @@ Effectuez une mise à niveau vers la dernière version d'Astro et mettez à nive ```ts title="src/content.config.ts" // Importer le chargeur glob import { glob } from "astro/loaders"; - // Importer des utilitaires depuis `astro:content` - import { z, defineCollection } from "astro:content"; + // Importer des utilitaires depuis `astro:content` et `astro/zod` + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // Définir un chargeur (`loader`) et un schéma (`schema`) pour chaque collection const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/it/tutorial/6-islands/4.mdx b/src/content/docs/it/tutorial/6-islands/4.mdx index 0e5ca0a650933..ad8866e02a09c 100644 --- a/src/content/docs/it/tutorial/6-islands/4.mdx +++ b/src/content/docs/it/tutorial/6-islands/4.mdx @@ -115,8 +115,9 @@ Aggiorna all'ultima versione di Astro e aggiorna tutte le integrazioni alle loro ```ts title="src/content.config.ts" // Importa il glob loader import { glob } from "astro/loaders"; - // Importa utilità da `astro:content` - import { z, defineCollection } from "astro:content"; + // Importa utilità da `astro:content` e `astro/zod` + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // Definisci un `loader` e uno `schema` per ogni raccolta const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/ja/guides/integrations-guide/mdx.mdx b/src/content/docs/ja/guides/integrations-guide/mdx.mdx index 15910161672f8..ce34f33f5e8e9 100644 --- a/src/content/docs/ja/guides/integrations-guide/mdx.mdx +++ b/src/content/docs/ja/guides/integrations-guide/mdx.mdx @@ -101,7 +101,8 @@ MDXインテグレーションを追加すると、JSX変数、式、コンポ コンテンツコレクションにMDXファイルを含めるには、[コレクションローダー](/ja/guides/content-collections/)が`.mdx`ファイルからコンテンツをロードするように設定されていることを確認してください。 ```js title="src/content.config.ts" ins="mdx" -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/ko/guides/content-collections.mdx b/src/content/docs/ko/guides/content-collections.mdx index 20e512f1a6fa8..68fedb3bf3ba1 100644 --- a/src/content/docs/ko/guides/content-collections.mdx +++ b/src/content/docs/ko/guides/content-collections.mdx @@ -64,7 +64,8 @@ Astro v5.0에서는 콘텐츠 컬렉션을 정의하고 쿼리하기 위한 Cont ```ts title="src/content.config.ts" // 1. `astro:content`에서 유틸리티 가져오기 -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; // 2. 로더 가져오기 import { glob, file } from 'astro/loaders'; @@ -89,8 +90,9 @@ Astro는 로컬 콘텐츠를 가져오기 위한 [두 가지 내장 로더 함 [`file()` 로더](/ko/reference/content-loader-reference/#file-로더)는 단일 로컬 파일에서 여러 항목을 생성합니다. 파일의 각 항목에는 고유한 `id` 키 속성이 있어야 합니다. 이 로더는 파일의 `base` 파일 경로를 인자로 받고 자동으로 분석할 수 없는 파일을 위해 선택적으로 [`parser` 함수](#parser-함수)를 인자로 받습니다. 데이터 파일을 객체 배열로 구문 분석할 수 있는 경우 이 로더를 사용합니다. -```ts title="src/content.config.ts" {5,9} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {6,10} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; // 레거시 API에서는 사용 불가능 const blog = defineCollection({ @@ -210,8 +212,9 @@ Astro가 새 스키마 또는 업데이트된 스키마를 인식하려면 개 컬렉션 항목의 모든 프런트매터나 데이터 속성은 Zod 데이터 타입을 사용하여 정의되어야 합니다: -```ts title="src/content.config.ts" {6-11,15-19} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {7-12,16-20} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; // 레거시 API에서는 사용 불가능 const blog = defineCollection({ @@ -286,7 +289,8 @@ Collections API의 [`reference()` 함수](/ko/reference/modules/astro-content/#r 일반적인 예시로는 JSON으로 저장된 재사용 가능한 작성자 프로필을 참조하거나, 같은 컬렉션에 저장된 관련 게시물 URL을 참조하는 블로그 게시물이 있습니다: ```ts title="src/content.config.ts" -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/ko/guides/images.mdx b/src/content/docs/ko/guides/images.mdx index 1deb607658b58..a478621ed75fe 100644 --- a/src/content/docs/ko/guides/images.mdx +++ b/src/content/docs/ko/guides/images.mdx @@ -594,7 +594,8 @@ This is a blog post 콘텐츠 컬렉션 스키마의 `image` 도우미를 사용하면 이미지를 검증하고 가져올 수 있습니다. ```ts title="src/content.config.ts" -import { defineCollection, z } from "astro:content"; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: ({ image }) => z.object({ diff --git a/src/content/docs/ko/guides/integrations-guide/mdx.mdx b/src/content/docs/ko/guides/integrations-guide/mdx.mdx index 7f1907d335a3f..2f16288d62b86 100644 --- a/src/content/docs/ko/guides/integrations-guide/mdx.mdx +++ b/src/content/docs/ko/guides/integrations-guide/mdx.mdx @@ -101,7 +101,8 @@ MDX 통합을 추가하면 JSX 변수, 표현식, 컴포넌트로 Markdown을 콘텐츠 컬렉션에 MDX 파일을 포함하려면, [컬렉션 로더](/ko/guides/content-collections/#컬렉션-loader-정의)가 `.mdx` 파일의 콘텐츠를 로드하도록 구성되어 있는지 확인하세요: ```js title="src/content.config.ts" ins="mdx" -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/ko/recipes/i18n.mdx b/src/content/docs/ko/recipes/i18n.mdx index 9adf5b51aaa91..d63b79ae81236 100644 --- a/src/content/docs/ko/recipes/i18n.mdx +++ b/src/content/docs/ko/recipes/i18n.mdx @@ -88,7 +88,8 @@ v4.0에서 Astro는 기본 및 지원되는 언어를 구성할 수 있게 해 ```ts //src/content.config.ts - import { defineCollection, z } from 'astro:content'; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: z.object({ diff --git a/src/content/docs/ko/reference/content-loader-reference.mdx b/src/content/docs/ko/reference/content-loader-reference.mdx index 94b87b237ec0c..14df9fe06e28e 100644 --- a/src/content/docs/ko/reference/content-loader-reference.mdx +++ b/src/content/docs/ko/reference/content-loader-reference.mdx @@ -181,7 +181,7 @@ const countries = defineCollection({ ```ts title=loader.ts import type { Loader, LoaderContext } from 'astro/loaders'; -import { z } from 'astro:content'; +import { z } from 'astro/zod'; import { loadFeedData } from "./feed.js"; // 로더에 필요한 모든 옵션을 정의 @@ -207,8 +207,9 @@ export function myLoader(options: { url: string, apiKey: string }): Loader { 이러한 구성 옵션은 컬렉션을 정의할 때 설정할 수 있습니다: -```ts title="src/content.config.ts" {2,5-8} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {3,6-9} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import myLoader from '../../loader.ts'; const blog = defineCollection({ diff --git a/src/content/docs/ko/reference/legacy-flags.mdx b/src/content/docs/ko/reference/legacy-flags.mdx index 3ba04e4329d8a..e2f47a97107b3 100644 --- a/src/content/docs/ko/reference/legacy-flags.mdx +++ b/src/content/docs/ko/reference/legacy-flags.mdx @@ -42,9 +42,10 @@ export default defineConfig({ ```js // src/content/config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blog = defineCollection({ }) - + export const collections = { blog }; ``` diff --git a/src/content/docs/ko/reference/modules/astro-content.mdx b/src/content/docs/ko/reference/modules/astro-content.mdx index 07897ddc2b4c0..5878c79f95b06 100644 --- a/src/content/docs/ko/reference/modules/astro-content.mdx +++ b/src/content/docs/ko/reference/modules/astro-content.mdx @@ -18,7 +18,6 @@ import ReadMore from '~/components/ReadMore.astro'; ```js import { - z, defineCollection, getCollection, getEntry, @@ -38,7 +37,8 @@ import { `defineCollection()`은 `src/content.config.*` 파일에 컬렉션을 구성하는 유틸리티입니다. ```ts title="src/content.config.ts" -import { z, defineCollection } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ @@ -92,7 +92,8 @@ export const collections = { blog }; 이 예시에서는 `authors` 컬렉션에 대한 블로그 작성자의 참조와 동일한 `blog` 컬렉션에 대한 관련 게시물 배열을 정의합니다. ```ts -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; const blog = defineCollection({ @@ -302,7 +303,8 @@ async function queryCollection(collection: CollectionKey) { - `image` - [콘텐츠 컬렉션에서 로컬 이미지를 사용](/ko/guides/images/#콘텐츠-컬렉션의-이미지)할 수 있게 해주는 `image()` 스키마 도우미 ```ts -import { defineCollection, z, type SchemaContext } from "astro:content"; +import { defineCollection, type SchemaContext } from "astro:content"; +import { z } from "astro/zod"; export const imageSchema = ({ image }: SchemaContext) => z.object({ diff --git a/src/content/docs/ko/tutorial/6-islands/4.mdx b/src/content/docs/ko/tutorial/6-islands/4.mdx index ac08119fbc381..996f93252a33c 100644 --- a/src/content/docs/ko/tutorial/6-islands/4.mdx +++ b/src/content/docs/ko/tutorial/6-islands/4.mdx @@ -120,7 +120,8 @@ import { Steps } from '@astrojs/starlight/components'; // glob 로더 가져오기 import { glob } from "astro/loaders"; // `astro:content`에서 유틸리티 가져오기 - import { z, defineCollection } from "astro:content"; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // 각 컬렉션에 대한 `loader` 및 `schema` 정의 const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/pt-br/reference/legacy-flags.mdx b/src/content/docs/pt-br/reference/legacy-flags.mdx index 0ce4ef929331d..6a7aec104ece6 100644 --- a/src/content/docs/pt-br/reference/legacy-flags.mdx +++ b/src/content/docs/pt-br/reference/legacy-flags.mdx @@ -43,9 +43,10 @@ Quando você estiver pronto para remover essa flag e migrar suas coleções lega ```js // src/content/config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blog = defineCollection({ }) - + export const collections = { blog }; ``` diff --git a/src/content/docs/pt-br/tutorial/6-islands/4.mdx b/src/content/docs/pt-br/tutorial/6-islands/4.mdx index 79ea4987e4ba6..18967fffe9c89 100644 --- a/src/content/docs/pt-br/tutorial/6-islands/4.mdx +++ b/src/content/docs/pt-br/tutorial/6-islands/4.mdx @@ -115,8 +115,9 @@ Atualize para a última versão do Astro, e atualize todas as integrações para ```ts title="src/content.config.ts" // Importe o glob loader import { glob } from "astro/loaders"; - // Importe utilidades de `astro:content` - import { z, defineCollection } from "astro:content"; + // Importe utilidades de `astro:content` e `astro/zod` + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // Defina um `loader` e `schema` para cada coleção const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/ru/recipes/i18n.mdx b/src/content/docs/ru/recipes/i18n.mdx index 2f8d62b5134a3..035e061dad12e 100644 --- a/src/content/docs/ru/recipes/i18n.mdx +++ b/src/content/docs/ru/recipes/i18n.mdx @@ -88,7 +88,8 @@ import StaticSsrTabs from '~/components/tabs/StaticSsrTabs.astro'; ```ts //src/content.config.ts - import { defineCollection, z } from 'astro:content'; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: z.object({ diff --git a/src/content/docs/ru/tutorial/6-islands/4.mdx b/src/content/docs/ru/tutorial/6-islands/4.mdx index bec07253313a2..c5914f7ce0aeb 100644 --- a/src/content/docs/ru/tutorial/6-islands/4.mdx +++ b/src/content/docs/ru/tutorial/6-islands/4.mdx @@ -116,7 +116,8 @@ import { Steps } from '@astrojs/starlight/components'; // Импортируем загрузчик glob import { glob } from "astro/loaders"; // Импортируем утилиты из `astro:content` - import { z, defineCollection } from "astro:content"; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // Определяем `loader` и `schema` для каждой коллекции const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/content/docs/zh-cn/guides/content-collections.mdx b/src/content/docs/zh-cn/guides/content-collections.mdx index d00fae769942e..9e4b1ad317f15 100644 --- a/src/content/docs/zh-cn/guides/content-collections.mdx +++ b/src/content/docs/zh-cn/guides/content-collections.mdx @@ -66,7 +66,8 @@ Astro 5.0 引入了内容层(Content Layer)API,用于定义和查询内容 ```ts title="src/content.config.ts" // 1. 从 `astro:content` 导入工具函数 -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; // 2. 导入加载器 import { glob, file } from 'astro/loaders'; @@ -91,8 +92,9 @@ Astro 提供了 [两个内置的加载器函数(`glob()` 和 `file()`)](/zh- [`file()` 加载器](/zh-cn/reference/content-loader-reference/#file-加载器) 从单个本地文件创建多个条目。文件中的每个条目必须有一个唯一的 `id` 键属性。它接受一个 相对你的文件的 `base` 文件路径,以及一个可选的 [`parser` 函数](#parser-函数) 用于它无法自动解析的数据文件。当你的数据文件可以解析为对象数组时,请使用此加载器。 -```ts title="src/content.config.ts" {5,9} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {6,10} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; // 不适用于旧版 API const blog = defineCollection({ @@ -212,8 +214,9 @@ const countries = defineCollection({ 集合条目的每个 frontmatter 或数据属性都必须使用 Zod 数据类型定义: -```ts title="src/content.config.ts" {6-11,15-19} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {7-12,16-20} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; // 不适用于旧版 API const blog = defineCollection({ @@ -288,7 +291,8 @@ defineCollection({ 一个常见的例子是一个引用存储为 JSON 的可重用作者配置文件的博客文章,或者存储在同一集合中的相关文章 URL: ```ts title="src/content.config.ts" -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/zh-cn/guides/images.mdx b/src/content/docs/zh-cn/guides/images.mdx index 864f58aaf9ac2..15b54d054daa5 100644 --- a/src/content/docs/zh-cn/guides/images.mdx +++ b/src/content/docs/zh-cn/guides/images.mdx @@ -589,7 +589,8 @@ coverAlt: "一张山脉后面的日落照片。" 内容集合 schema 中的 `image` 助手允许你验证并导入图像。 ```ts title="src/content.config.ts" -import { defineCollection, z } from "astro:content"; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: ({ image }) => z.object({ diff --git a/src/content/docs/zh-cn/guides/integrations-guide/mdx.mdx b/src/content/docs/zh-cn/guides/integrations-guide/mdx.mdx index fff267ef647bf..85cbb9be230ec 100644 --- a/src/content/docs/zh-cn/guides/integrations-guide/mdx.mdx +++ b/src/content/docs/zh-cn/guides/integrations-guide/mdx.mdx @@ -100,7 +100,8 @@ export default defineConfig({ 要将 MDX 文件包含在内容集合中,请确保你的 [集合 loader](/zh-cn/guides/content-collections/#定义集合-loader) 配置为从 `.mdx` 文件加载内容: ```js title="src/content.config.ts" ins="mdx" -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ diff --git a/src/content/docs/zh-cn/recipes/i18n.mdx b/src/content/docs/zh-cn/recipes/i18n.mdx index 2db260f868956..335e65f005baa 100644 --- a/src/content/docs/zh-cn/recipes/i18n.mdx +++ b/src/content/docs/zh-cn/recipes/i18n.mdx @@ -87,7 +87,8 @@ import StaticSsrTabs from '~/components/tabs/StaticSsrTabs.astro'; ```ts //src/content.config.ts - import { defineCollection, z } from 'astro:content'; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; const blogCollection = defineCollection({ schema: z.object({ diff --git a/src/content/docs/zh-cn/reference/content-loader-reference.mdx b/src/content/docs/zh-cn/reference/content-loader-reference.mdx index 90d9bb832ed2a..c8cf82e8fca8a 100644 --- a/src/content/docs/zh-cn/reference/content-loader-reference.mdx +++ b/src/content/docs/zh-cn/reference/content-loader-reference.mdx @@ -182,7 +182,7 @@ const countries = defineCollection({ ```ts title=loader.ts import type { Loader, LoaderContext } from 'astro/loaders'; -import { z } from 'astro:content'; +import { z } from 'astro/zod'; import { loadFeedData } from "./feed.js"; // 定义加载器需要的任何选项 @@ -208,8 +208,9 @@ export function myLoader(options: { url: string, apiKey: string }): Loader { 然后就可以在定义集合时设置这些配置选项: -```ts title="src/content.config.ts" {2,5-8} -import { defineCollection, z } from 'astro:content'; +```ts title="src/content.config.ts" {3,6-9} +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import myLoader from '../../loader.ts'; const blog = defineCollection({ diff --git a/src/content/docs/zh-cn/reference/legacy-flags.mdx b/src/content/docs/zh-cn/reference/legacy-flags.mdx index 33972dbcdc368..f9ce0ca6a29ee 100644 --- a/src/content/docs/zh-cn/reference/legacy-flags.mdx +++ b/src/content/docs/zh-cn/reference/legacy-flags.mdx @@ -42,9 +42,10 @@ export default defineConfig({ ```js // src/content/config.ts -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; const blog = defineCollection({ }) - + export const collections = { blog }; ``` diff --git a/src/content/docs/zh-cn/reference/modules/astro-content.mdx b/src/content/docs/zh-cn/reference/modules/astro-content.mdx index 8e7205f8f2d87..25f2efbc0b336 100644 --- a/src/content/docs/zh-cn/reference/modules/astro-content.mdx +++ b/src/content/docs/zh-cn/reference/modules/astro-content.mdx @@ -18,7 +18,6 @@ import ReadMore from '~/components/ReadMore.astro'; ```js import { - z, defineCollection, getCollection, getEntry, @@ -39,7 +38,8 @@ import { `defineCollection()` 是一个用于在 `src/content.config.*` 文件中配置集合的工具函数。 ```ts title="src/content/config.js" -import { z, defineCollection } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { z } from "astro/zod"; import { glob } from 'astro/loaders'; const blog = defineCollection({ @@ -94,7 +94,8 @@ export const collections = { blog }; 此示例定义了从博客作者到 `authors` 集合的引用,以及到同一 `blog` 集合的相关文章数组的引用: ```ts -import { defineCollection, reference, z } from 'astro:content'; +import { defineCollection, reference } from "astro:content"; +import { z } from "astro/zod"; import { glob, file } from 'astro/loaders'; const blog = defineCollection({ @@ -307,7 +308,8 @@ async function queryCollection(collection: CollectionKey) { - `image` - `image()` schema 辅助工具允许你 [在内容集合中使用本地图片](/zh-cn/guides/images/#内容集合中的图像)。 ```ts -import { defineCollection, z, type SchemaContext } from "astro:content"; +import { defineCollection, type SchemaContext } from "astro:content"; +import { z } from "astro/zod"; export const imageSchema = ({ image }: SchemaContext) => z.object({ diff --git a/src/content/docs/zh-cn/tutorial/6-islands/4.mdx b/src/content/docs/zh-cn/tutorial/6-islands/4.mdx index 695af8baf0fe6..75f2e84b15662 100644 --- a/src/content/docs/zh-cn/tutorial/6-islands/4.mdx +++ b/src/content/docs/zh-cn/tutorial/6-islands/4.mdx @@ -119,7 +119,8 @@ import { Steps } from '@astrojs/starlight/components'; // 导入 glob 加载器(loader) import { glob } from "astro/loaders"; // 从 `astro:content` 导入工具函数 - import { z, defineCollection } from "astro:content"; + import { defineCollection } from "astro:content"; + import { z } from "astro/zod"; // 为每个集合定义一个 `loader` 和 `schema` const blog = defineCollection({ loader: glob({ pattern: '**/[^_]*.md', base: "./src/blog" }), diff --git a/src/data/logos.ts b/src/data/logos.ts index cc3fe7e1896fc..69d779e9886c1 100644 --- a/src/data/logos.ts +++ b/src/data/logos.ts @@ -1,4 +1,4 @@ -import { z } from 'astro:content'; +import { z } from 'astro/zod'; /** Enforce logo types while preserving exact key type. */ const LogoCheck = >(logos: T) => logos;