保存为 .yaml 格式时,Netlify CMS 不包含连字符

Netlify CMS isn't including the hyphen when saving as .yaml format

我将 Gatsby 与 gatsby-plugin-netlify-cms 结合使用以将 Netlify CMS 添加到网站,netlify-cms-backend-fs 以允许 Netlify CMS 使用文件系统而不是远程存储库在开发模式下工作,并且 gatsby-transformer-yaml 转换 yaml 文件,以便可以通过 GraphQL 查询访问它。

相关代码如下:

// src/cms/cms.js
import CMS from "netlify-cms-app";

/** Netlify CMS config */
const config = {
  load_config_file: false,
  media_folder: "static/img",
  public_folder: "img",
  collections: [
    {
      label: "Business Details",
      name: "business",
      files: [
        {
          label: "Contact Information",
          name: "contactInfo",
          file: "data/business.yaml",
          fields: [
            { label: "Title", name: "title" },
            { label: "Business Name", name: "name" },
            { label: "Phone Number", name: "phone" },
            { label: "Email", name: "email" }
          ]
        }
      ]
    }
  ]
};

/** Change to file system backend for development  */
if (process.env.NODE_ENV === "development") {
  const FileSystemBackend = require("netlify-cms-backend-fs");
  config.backend = {
    name: "file-system",
    api_root: "/api"
  };
  config.display_url = "http://localhost:8000";
  CMS.registerBackend("file-system", FileSystemBackend);
} else {
  config.backend = {
    backend: {
      name: "test-repo" // To be changed to repo when ready for deployment
    }
  };
}

CMS.init({ config });

我能够访问 Netlify CMS 仪表板,创建新条目并发布它。但是当它发布时,data/business.yaml 的内容是:

title: Business Details
name: My Business Name
phone: 555-5555
email: me@example.com

这个 应该 格式改为(注意连字符和缩进):

- title: Business Details
  name: My Business Name
  phone: 555-5555
  email: me@example.com

结果是我无法使用以下方法查询此数据:

query MyQuery {
  allBusinessYaml {
    edges {
      node {
        email
        name
        phone
      }
    }
  }
}

因为 allBusinessYaml 不存在。

如果我手动将 data/business.yaml 文件更改为带有连字符和缩进的正确格式,此错误将得到解决。

我试过将小部件设置为 objectlist,并尝试将 formatextension 显式设置为 yaml,但这并没有也解决问题。例如

const config = {
  load_config_file: false,
  media_folder: "static/img",
  public_folder: "img",
  collections: [
    {
      label: "Business Details",
      name: "business",
      files: [
        {
          label: "Contact Information",
          name: "contactInfo",
          file: "data/business.yaml",
          format: "yaml",
          extension: "yaml",
          widget: "list", // NOTE: I've also tried using "object" here
          fields: [
            { label: "Title", name: "title" },
            { label: "Business Name", name: "name" },
            { label: "Phone Number", name: "phone" },
            { label: "Email", name: "email" }
          ]
        }
      ]
    }
  ]
};

我做错了什么?

Netlify CMS 尚不支持顶级列表 - 这是要遵循的问题:https://github.com/netlify/netlify-cms/issues/531