Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 内容丰富的CMS数据层未到达我的Gatsby/React博客_Javascript_Reactjs_Content Management System_Gatsby_Contentful - Fatal编程技术网

Javascript 内容丰富的CMS数据层未到达我的Gatsby/React博客

Javascript 内容丰富的CMS数据层未到达我的Gatsby/React博客,javascript,reactjs,content-management-system,gatsby,contentful,Javascript,Reactjs,Content Management System,Gatsby,Contentful,我以前在盖茨比数据层使用local.md文件,但现在我需要有内容的CMS集成 const Promise = require('bluebird') const path = require('path') exports.createPages = ({ graphql, boundActionCreators }) => { const { createPage } = boundActionCreators return new Promise((resolve, reject)

我以前在盖茨比数据层使用local.md文件,但现在我需要有内容的CMS集成

const Promise = require('bluebird')
const path = require('path')

exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators

return new Promise((resolve, reject) => {
const blogPost = path.resolve('./src/templates/blog-post.js')

resolve(
  graphql(
    `
      {
        allContentfulBlog(limit: 500) {
          edges {
            node {
              id
              slug
            }
          }
        }
      }
    `
  ).then(result => {
    if (result.errors) {
      console.log(result.errors)
      reject(result.errors)
    }
    result.data.allContentfulBlog.edges.forEach(edge => {
      createPage({
        path: edge.node.slug,
        component: blogPost,
        context: {
          slug: edge.node.slug,
        },
      })
    })
    return
   })
  )
 })
}

exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
  const { createNodeField } = boundActionCreators
}
这是我的gatsby-node.js文件

终端提供:

TypeError:无法读取未定义的属性“allContentfulBlog”

在Contentful.com上,内容类型的名称为Blog

我附上了终端的截图

有任何提示吗?

看起来

TypeError:无法读取未定义的属性“allContentfulBlog”

是由于

无法查询“ContentfulBlog”类型上的字段“slug”


你能分享你的内容模型吗?我不知道你有没有看过盖茨比满意的开场白。它附带了一个内容模型,因此您也可以在那里查看。:)

您好,我如何在这里共享内容模型?不,我不知道盖茨比知足初学者的存在,谢谢,我会去看看。对于这个问题,也许一些截图就足够了。但一般来说,共享内容模型
内容导入
内容导出
是使用的工具。它们可在npm上获得。:)我最终删除了exports.onCreateNode函数,该函数负责根据我从gatsby starter博客插件获得的标题(我想)创建slug,一切似乎都很好。