Astro 构建在 netlify 中失败

问题描述 投票:0回答:1

因此,我按照官方教程的建议设置了 astro:https://docs.astro.build/en/tutorial/0-introduction/。我进一步按照他们建议的内容集合进行操作https://docs.astro.build/en/tutorials/add-content-collections/。 然后我按照此处教程的建议设置 decap cms https://docs.astro.build/en/guides/cms/decap-cms/.

一切正常,设置完美无缺。一切都在 git commit 后正确部署。 然后我在 decap cms 中登录 mysite/admin 。我制作了一篇演示博客文章,然后尝试发布它。但netlify中总是出现构建错误。

这是我遇到的错误。

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)

我搜索了一些文档,并了解到 config.yml 文件应该使用我的 config.ts 架构对集合进行适当排序。

这是我的config.ts(文件位置:/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,
};

这是config.yml(文件位置:/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"}

**我应该如何继续解决这个问题?
**
预先感谢。

yaml config blogs astro decap-cms
1个回答
0
投票

关于 Netlify 上的 Astro 构建,您能否提供有关您看到的错误消息或日志的更多详细信息?对于非官方 Stack Overflow 应用程序的登录问题,您是否检查过您的互联网连接并验证了您的登录凭据?如果需要,请尝试清除应用程序缓存或重新安装。如果您需要进一步帮助,请告诉我们。

致以诚挚的问候,

兹万斯基·穆罕默德

© www.soinside.com 2019 - 2024. All rights reserved.