我正在用 gatsby 和 Netlify CMS 构建一个站点。我使用了 Gatsby Site Starter。
我不断收到“文件”类型的“GraphQL 错误字段“图像”必须有一个子字段选择。您的意思是“图像 { ... }”吗?尝试部署到 Netlify 时出错。一切都在本地主机上完美运行,但图像似乎有些失败。我查看了 Netlify CMS 页面上提供的示例,发现有人具有完全相同的设置,一个列表小部件(充当画廊),里面有图像和描述,here。
配置.yml
backend:
name: git-gateway
repo: grantballmer/gatsby-starter-netlify-cms
branch: master
media_folder: static/img
public_folder: /img
collections:
- name: "gallery"
label: "Gallery"
folder: "src/pages/services"
create: true
fields:
- { label: "Template Key", name: "templateKey", widget: "hidden", default: "gallery" }
- {label: "Title", name: "title", widget: "string"}
- label: "Grid"
name: "grid"
widget: "list"
fields:
- {label: "Image", name: "image", widget: "image"}
- {label: "Band Name", name: "band", widget: "string"}`
gallery.js(模板文件)
import React from 'react';
import { graphql } from 'gatsby';
import Layout from "../components/Layout";
import PhotoGrid from "../components/services/PhotoGrid";
const GalleryTemplate = ({ data }) => {
const { markdownRemark: gallery } = data;
const images = gallery.frontmatter.grid;
return (
<Layout>
<PhotoGrid images={images} />
</Layout>
);
};
export default GalleryTemplate;
export const galleryQuery = graphql `
query Gallery($id: String!) {
markdownRemark(id: { eq: $id }) {
html
frontmatter {
title
grid {
image
band
}
}
}
}
`;
/服务/摄影.md
---
templateKey: 'gallery'
title: photography
grid:
- band: chris-cordle
image: /img/chris-cordle-lg.jpg
- band: 'chirp '
image: /img/chirp-lg-1-.jpg
---