nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.14k stars 628 forks source link

Inconsistent placement of custom fields form the .md files #2856

Open iBobik opened 2 days ago

iBobik commented 2 days ago

Environment

Version

3.0.0-alpha.6

Reproduction

https://codesandbox.io/p/devbox/brave-bogdan-8myc2y?workspaceId=11463712-f2b6-4ff2-abfc-9afdf4b3cb02

Description

When I place custom field in the front matter:

---
title: Example article
image: /images/products/test.jpeg
---

define schema for it (like recommanded in the docs):

  products: defineCollection({
    type: 'page',
    source: 'products/*.md',
    schema: z.object({
      image: z.string(),
    }),
  }),

Typing tells me the field is on the object root:

Image

But it actually is accesible in the meta subobject:

meta.image: /images/products/test.jpeg image:

Even if typing does not expect it there:

Image

farnabaz commented 2 days ago

This is related to cached data in .data/content directory. The next version will respect collection changes and will clear cache automatically.

But for now in alpha.6 you can remove .data/content directory in your project and restart Nuxt to force a re-index. This will solve the issue.