Recently, I ran into an issue while utilizing Astro with Content Collections where I needed to escape some special characters.
In my case, I wanted to add a dots character (:
) in the frontmatter YAML title of a markdown file.
If we simply add the dots like this:
title: Markdown frontmatter title: using dots
We will get the following error:
InvalidContentEntryFrontmatterErrorContent entry frontmatter does not match schema
We are going to see several solutions.
Using quotes"undefined" anchor link
The easiest solution is just to quote the title content.
title: 'Markdown frontmatter title: using dots'
Block scalar styles"undefined" anchor link
But also, we can use these two YAML block styles:
- YAML block scalar with folded style.
title: > Markdown frontmatter title: using dots
- YAML block scalar with literal style.
title: | Markdown frontmatter title: using dots
I hope you found this article useful.
Happy coding! 🚀