#A content collection in a single file

6 messages · Page 1 of 1 (latest)

steady wigeon
#

I'd like to define a content collection using Zod but have the entire collection in a single file rather than spread across many files

#

I'll try a basic example. Here's the schema:

const authors = defineCollection({
  type: "data",
  schema: z.object({
    name: z.string().min(1),
  }),
});

And now I want to just have an authors.yaml like this:

- name: Someone
- name: Someone else
#

My actual use case is much more complex but this should serve as a reasonable illustration

raven valve
#

I'm interested to learn if this can be done.
But, what I've done so far is put my data in \src\data\authors.json and then import it: import authors from "@data/authors.json". You don't have the benefits of zod, but you do get intellisense on authors.

hidden thicket
#

Could you just define an array of objects? Something like this:

const userInfoSchema = z.object({
  id: z.string(),
  name: z.string(),
  experience: z.number().optional()
})

// Now add this object into an array
const usersInfoSchema = z.array(userInfoSchema)
raven valve
#

Good idea, so basically a collection of one.