N
Nuxt2mo ago
tpluscode

Content: Missing frontmatter prop is substituted with body

I defined a "pages" collection from this initialization object
{
source: 'pages/*.md',
type: 'page',
schema: z.object({
title: z.string(),
heading: z.string().optional(),
description: z.string().optional(),
permalink: z.string().optional(),
})
}
{
source: 'pages/*.md',
type: 'page',
schema: z.object({
title: z.string(),
heading: z.string().optional(),
description: z.string().optional(),
permalink: z.string().optional(),
})
}
I then render a page (index.en.md) which does not have a description:
---
title: Home
---

The lazy dog jumps over the lazy fox.
---
title: Home
---

The lazy dog jumps over the lazy fox.
Here's how I load it in the page script
const {data: page} = await useAsyncData(route.path, () => {
const slug = route.params.id || 'index'

return queryCollection('pages')
.where('path', 'LIKE', `%${slug}.${locale.value}`)
.first()
})
const {data: page} = await useAsyncData(route.path, () => {
const slug = route.params.id || 'index'

return queryCollection('pages')
.where('path', 'LIKE', `%${slug}.${locale.value}`)
.first()
})
I expect empty description property but it gets populated with the body instead
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @tpluscode. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This behavior is expected in Nuxt Content. When the description property is not defined in the frontmatter of a Markdown file, Nuxt Content will automatically use the first paragraph (<p>) of the body as the description. This is documented as the default behavior for the description field:
| description | string | First <p> of the page | Description of the page, will be shown below the title and injected into the metas |
So, if you omit the description in your frontmatter, Nuxt Content will substitute it with the first paragraph of your content body. If you want the description to be empty, you need to explicitly set it as an empty string in your frontmatter:
---
title: Home
description: ""
---
The lazy dog jumps over the lazy fox.
---
title: Home
description: ""
---
The lazy dog jumps over the lazy fox.
This will ensure that the description property is empty, rather than being auto-filled from the body content.
See documentation on native parameters. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@555413648382623754> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?