-
-
Notifications
You must be signed in to change notification settings - Fork 98
Description
The error:
My frontmatter for the cover image is defined via Astro's content.config.ts schema:
cover: z
.union([
z.string(),
z.object({
src: z.string(),
title: z.string().optional(),
}),
])
.optional(),
which means both of the following are valid:
cover: some-filename.jpg
cover:
src: some-filename.jpg
title: a title for the file
In my frontmatter.json, I see no way to configure an "either or" for the field type of the cover:
"frontMatter.taxonomy.contentTypes": [
{
"name": "default",
...
"fields": [
...
{
"title": "Content preview",
"name": "cover",
"type": "image",
"isPreviewImage": true
}
]
}
]
With this frontmatter.json, the second cover
format is invalid (which is okay by me) and throws an error because an expected string does not have a .startsWith
method. The field needs to be typecast somehow before applying filters and transformations.
Is there a way to make Frontmatter understand two possible field formats, or have it ignore the field (not validate it)?
Even if not, it should not error loudly with a popup; instead, it should "simply" complain about incorrect frontmatter during the validation of the frontmatter when the file is opened/saved.