Reputation: 1
So I set up the astro as recommended by their official tutorial at https://docs.astro.build/en/tutorial/0-introduction/. I went further and did as they suggested for content collections https://docs.astro.build/en/tutorials/add-content-collections/. Then I set up the decap cms as suggested by the tutorial here https://docs.astro.build/en/guides/cms/decap-cms/.
Everything worked fine and the setup was flawless. Everything was deploying correctly upon git commit. Then I logged in mysite/admin in the decap cms. I made a demo blog post and then tried to publish it. But it is always having build error in netlify.
This is the error that I was encountering.
4:40:00 PM: **Failed during stage "building site": Build script returned non-zero exit code: 2**
4:40:00 PM: **[InvalidContentEntryFrontmatterError] posts → 2024-02-04-my-first-blog-post-through-cms.md frontmatter does not match collection schema.**
4:40:00 PM: pubDate: Required
4:40:00 PM: author: Required
4:40:00 PM: image: Required
4:40:00 PM: tags: Required
4:40:00 PM: Hint:
4:40:00 PM: See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.
4:40:00 PM: Error reference:
4:40:00 PM: https://docs.astro.build/en/reference/errors/invalid-content-entry-frontmatter-error/
4:40:00 PM: Stack trace:
4:40:00 PM: at getEntryData (file:///opt/build/repo/node_modules/astro/dist/content/utils.js:86:26)
4:40:00 PM: at async Object.transform (file:///opt/build/repo/node_modules/astro/dist/content/vite-plugin-content-imports.js:74:67)
4:40:00 PM: at async ModuleLoader.addModuleSource (file:///opt/build/repo/node_modules/rollup/dist/es/shared/node-entry.js:17810:36)
I searched some documentation and came to know that the config.yml file should have the collections appropriately ordered with my config.ts schema.
This is my config.ts (location of file: /src/content/config.ts)
// Import utilities from `astro:content`
import { z, defineCollection } from "astro:content";
// Define a `type` and `schema` for each collection
const postsCollection = defineCollection({
type: 'content',
schema: z.object({
title: z.string(),
pubDate: z.date(),
description: z.string(),
author: z.string(),
image: z.object({
url: z.string(),
alt: z.string().optional()
}),
tags: z.array(z.string())
})
});
// Export a single `collections` object to register your collection(s)
export const collections = {
posts: postsCollection,
};
This is config.yml(location of file: /public/admin/config.yml)
backend:
name: git-gateway
branch: main
publish_mode: editorial_workflow
media_folder: "src/assets"
public_folder: "assets"
collections:
- name: "postsCollection"
label: ""
folder: "/src/content/posts"
create: true
slug: "{{slug}}"
fields:
- {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "pubDate", widget: "datetime"}
- {label: "Description", name: "description", widget: "string"}
- {label: "Author", name: "author", widget: "string"}
- {label: "Featured Image", name: "image", widget: "image", fields: [
{label: "URL", name: "url", widget: "string"},
{label: "Alt Text", name: "alt", widget: "string"}
]}
- {label: "Tags", name: "tags", widget: "list", field: {label: "Tag", name: "tag", widget: "string"}}
- {label: "Body", name: "body", widget: "markdown"}
**How should I go on to solve this issue?
**
Thanks in advance.
Upvotes: 0
Views: 310
Reputation: 1
Issue solved for me by just matching the schema exactly in config.ts to the collections in config.yml
Upvotes: 0