N
Nuxt5mo ago
Lean

Nuxt content markdown validation

Is there a way to validate nuxt content .md files based on the collection schema ? So far, ive added categories: z.array(z.enum(VALID_CATEGORIES)).optional(), to schema of my collection, but when writing the content .md file, i can write whatever i want, i would get no warnings about it and it would still work correctly, even tho im guessing it should not.
3 Replies
kapa.ai
kapa.ai5mo ago
Hi @Lean. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Nuxt Content does validate your Markdown frontmatter and data files against the schema you define in your collection using Zod. This validation ensures type safety and consistency at build time, and the schema is the source of truth for your content structure Defining Collections. However, the current documentation does not mention any built-in feature that provides real-time warnings or errors directly in your editor when you write invalid values in your .md files. If you write a value in the frontmatter that does not match the schema (for example, a category not in your enum), the validation will only take effect at build time or when querying the content. Invalid values may result in the field being omitted or set to undefined, but you won't get an immediate warning in your code editor. If you use Nuxt Studio, the form editor is generated based on your schema and will restrict input to valid enum values, preventing invalid entries through the visual interface. But if you edit the Markdown files directly (e.g., in VS Code), you won't get schema-based validation feedback in real time Form Editor. In summary: - Schema validation is enforced at build time and when querying content. - The Studio form editor restricts input to valid schema values. - Direct editing of .md files does not provide real-time validation or warnings in your code editor. If you need stricter validation or editor integration, you may need to use external tools or custom scripts to lint your Markdown files according to your schema. References:
Defining Collections
Form Editor ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@401116245857927199> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Lean
LeanOP5mo ago
:/

Did you find this page helpful?