#Content Collection Entry Question

4 messages · Page 1 of 1 (latest)

hushed abyss
#

Is it possible to write collection entries without content, IE just the front matter/schema section so filled but nothing is after the fence?

pearl doveBOT
#

Hi @hushed abyss. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, it is possible to create a collection entry with just the front matter/schema section filled and no content after the fence. In Astro, a collection entry is any piece of content stored inside of your content collection directory. Entries can use content authoring formats including Markdown (.md) and MDX (.mdx) or as one of two supported data formats: YAML (.yaml) and JSON (.json).

However, it's important to note that the front matter must match the collection schema. If any file violates its collection schema, Astro will provide a helpful error to let you know. For instance, if a required field in the front matter is missing or of the wrong type, you might encounter an InvalidContentEntryFrontmatterError.

Here's an example of how you might define a collection schema in Astro:

// src/content/config.ts
import { z, defineCollection } from 'astro:content';

const blogCollection = defineCollection({  
  type: 'content', // v2.5.0 and later  
  schema: z.object({    
    title: z.string(),    
    tags: z.array(z.string()),    
    image: z.string().optional(),  
  }),
});

export const collections = {  
  'blog': blogCollection,
};

In this example, the blog collection requires a title and tags in the front matter of each entry, and optionally an image. As long as these requirements are met, it's perfectly fine to have an entry with no content after the front matter.