You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/en/guides/content-collections.mdx
+63-40Lines changed: 63 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,13 +208,16 @@ Your blog post content here.
208
208
You can also pass options to the `glob()` loader's [`generateID()` helper function](/en/reference/content-loader-reference/#generateid) when you define your build-time collection to adjust how `id`s are generated. For example, you may wish to revert the default behavior of converting uppercase letters to lowercase for each collection entry:
209
209
210
210
```js title="src/content.config.ts"
211
+
import { glob } from"astro/loaders";
212
+
import { defineCollection } from"astro:content";
213
+
211
214
constauthors=defineCollection({
212
215
/* Retrieve all JSON files in your authors directory while retaining
The [`file()` loader](/en/reference/content-loader-reference/#file-loader) fetches multiple entries from a single local file defined in your collection. The `file()` loader will automatically detect and parse (based on the file extension) a single array of objects from JSON and YAML files, and will treat each top-level table as an independent entry in TOML files.
225
228
226
229
```ts title="src/content.config.ts" {5}
227
-
import { defineCollection } from'astro:content';
228
-
import { file } from'astro/loaders';
230
+
import { defineCollection } from"astro:content";
231
+
import { file } from"astro/loaders";
229
232
230
233
const dogs =defineCollection({
231
234
loader: file("src/data/dogs.json"),
@@ -301,8 +304,8 @@ You can [build a custom loader](/en/reference/content-loader-reference/#building
301
304
Then you can import and define your custom loader in your collections config, passing any required values:
302
305
303
306
```ts title="src/content.config.ts"
304
-
import { defineCollection } from'astro:content';
305
-
import { myLoader } from'./loader.ts';
307
+
import { defineCollection } from"astro:content";
308
+
import { myLoader } from"./loader.ts";
306
309
307
310
const blog =defineCollection({
308
311
loader: myLoader({
@@ -335,9 +338,9 @@ In order for Astro to recognize a new or updated schema, you may need to restart
335
338
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](/en/reference/modules/astro-zod/#common-data-type-validators):
0 commit comments