From a366c9b4f542f9728e3c253543871e596fab5b31 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 10 Jan 2023 18:33:06 -0500 Subject: [PATCH 1/3] edit: add type gen to setup --- src/pages/en/guides/content-collections.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/en/guides/content-collections.mdx b/src/pages/en/guides/content-collections.mdx index c409bf6ad27d0..5bc6da200fece 100644 --- a/src/pages/en/guides/content-collections.mdx +++ b/src/pages/en/guides/content-collections.mdx @@ -36,6 +36,8 @@ export default defineConfig({ }); ``` +Then, run `astro dev`, `astro build`, or `astro sync` to generate types. This will make the `astro:content` module available for querying and configuring your content collections. + ### Update TypeScript configuration To benefit from the full TypeScript and autocompletion features of [using schemas with your collections](#defining-a-collection-schema), you may also need to update `tsconfig.json`. Follow the instructions below based on your Astro project's current [TypeScript configuration](/en/guides/typescript/#setup). From ca3d26653212aea9145e9a41d27f3734d4a0032d Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 10 Jan 2023 18:37:20 -0500 Subject: [PATCH 2/3] edit: add tips where `astro:content` is used --- src/pages/en/guides/content-collections.mdx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/en/guides/content-collections.mdx b/src/pages/en/guides/content-collections.mdx index 5bc6da200fece..457abdcef9d13 100644 --- a/src/pages/en/guides/content-collections.mdx +++ b/src/pages/en/guides/content-collections.mdx @@ -137,6 +137,10 @@ To configure schemas, create a `src/content/config.ts` file (`.js` and `.mjs` ex 2. Define a `schema` for each collection. 2. Export a single `collections` object, with each object key corresponding to the collection's folder name. +:::tip +Run `astro dev`, `astro build`, or `astro sync` before using the `astro:content` module. These commands will generate types for utilities like `defineCollection`. +::: + For example, say you maintain two collections: one for release announcements and one for blog content. Your entries at `src/content/releases/` should include a `title` and `version`. Your `src/content/engineering-blog/` collection entries should have a `title`, list of `tags`, and an optional `image` URL. You can specify each expected property in the `schema` field of `defineCollection`: @@ -240,6 +244,10 @@ export const collections = { blog }; ## Querying content collections +:::tip +Run `astro dev`, `astro build`, or `astro sync` before using the `astro:content` module. These commands will generate types for utilities like `getCollection()` and `getEntry()`. +::: + Astro provides two functions to query collections: ### `getCollection()` From 8c20e2b1994b4e07c6208be374480f2a35196cc1 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 10 Jan 2023 18:38:36 -0500 Subject: [PATCH 3/3] edit: defineCollection -> defineCollection() --- src/pages/en/guides/content-collections.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/content-collections.mdx b/src/pages/en/guides/content-collections.mdx index 457abdcef9d13..64daba163a9d1 100644 --- a/src/pages/en/guides/content-collections.mdx +++ b/src/pages/en/guides/content-collections.mdx @@ -138,7 +138,7 @@ To configure schemas, create a `src/content/config.ts` file (`.js` and `.mjs` ex 2. Export a single `collections` object, with each object key corresponding to the collection's folder name. :::tip -Run `astro dev`, `astro build`, or `astro sync` before using the `astro:content` module. These commands will generate types for utilities like `defineCollection`. +Run `astro dev`, `astro build`, or `astro sync` before using the `astro:content` module. These commands will generate types for utilities like `defineCollection()`. ::: For example, say you maintain two collections: one for release announcements and one for blog content. Your entries at `src/content/releases/` should include a `title` and `version`. Your `src/content/engineering-blog/` collection entries should have a `title`, list of `tags`, and an optional `image` URL.