使用netlifyCMS和Gatsby的“找不到后端”

时间:2019-04-01 21:24:54

标签: gatsby netlify netlify-cms

我一直在尝试通过克隆gatsby-starter-default在一个非常基本的Gatsby应用上设置NetlifyCMS。我遵循了Sourcing from Netlify CMS instructions,但我不断遇到“找不到后端”错误。这是我的盖茨比设置:

/static/admin/config.yml

backend:
  name: appendtoStatic
  branch: master

media_folder: static/img
public_folder: /images

collections:
  - name: "pages"
    label: "Pages"
    files:    
      - file: "src/pages/about.md"
        label: "About"
        name: "about"
        fields:
          - {
              label: "Template Key",
              name: "templateKey",
              widget: "hidden",
              default: "about-page",
            }
          - { label: "Title", name: "title", widget: "string" }
          - { label: "Body", name: "body", widget: "markdown" }

这是我的package.json

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "gatsby": "^2.2.3",
    "gatsby-image": "^2.0.34",
    "gatsby-plugin-manifest": "^2.0.24",
    "gatsby-plugin-netlify-cms": "^3.0.17",
    "gatsby-plugin-offline": "^2.0.25",
    "gatsby-plugin-react-helmet": "^3.0.10",
    "gatsby-plugin-sharp": "^2.0.30",
    "gatsby-source-filesystem": "^2.0.27",
    "gatsby-transformer-remark": "^2.3.8",
    "gatsby-transformer-sharp": "^2.1.17",
    "netlify-cms": "^2.9.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.4",
    "react-dom": "^16.8.4",
    "react-helmet": "^5.2.0"
  },
  "devDependencies": {
    "prettier": "^1.16.4"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write src/**/*.{js,jsx}",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

我的gatsby-config.js

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `src`,
        path: `${__dirname}/src/`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-transformer-remark`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    `gatsby-plugin-netlify-cms`,
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // 'gatsby-plugin-offline',
  ],
}

在我的一生中,我无法弄清楚为什么这行不通。

我尝试了NetlifyCMS文档中的Sourcing中的确切教程,并使其正常工作。我不确定为什么将netlifyCMS添加到默认Gatsby启动程序的原因/地点/方式失败...

enter image description here

1 个答案:

答案 0 :(得分:1)

在您的config.yml中,后端名称应该是git服务,例如github,gitlab或bitbucket,并且您的回购名称会列在repo字段中。

docs:

中的示例
backend:
  name: github
  repo: owner-name/repo-name