I'd like to organize my content into multiple directories, which from what I've read means I need multiple collections, but they would all have the same schema. There will be a few more fields in the future, but basically my config looks like this:
const basicPageConfig = {
schema: z.object({
title: z.string(),
}),
};
export const basicCollections = {
foundation: defineCollection(basicPageConfig),
guidelines: defineCollection(basicPageConfig),
// ...more 'basic page' collections
} as const;
export type BasicCollection = keyof typeof basicCollections;
export const collections = {
blog,
...basicCollections,
};
I want to be able to use the same page layout component for all these "basic pages", and I want it to be typed. However, every time I try to call getCollection with a union type from these collection keys, the type returned by that function is never[].
// `collection` is type `BasicCollection`, and
// BasicCollection = "foundation" | "guidelines"
// But `posts` is `never[]`!
const posts = await getCollection(collection);
My conclusion is that the generic getCollection doesn't support union types. So how do I do what I'm doing? Is it possible to make them all part of the same collection but place them in different subdirectories in my content directory with matching paths in their URLs?