Gatsby节点api没有提供值“ fileAbsolutePath”

时间:2019-06-04 08:54:02

标签: node.js reactjs graphql

我正在我的个人网站上创建了“ markdown”文件的那个文件夹上创建了“ blogpost”。这样我就可以使用graphql

我使用了gatsby节点api“ onCreateNode”。您可以在此处https://www.gatsbyjs.org/docs/node-apis/#onCreateNode

签出

所以,这里我想从“ fileAbsolutePath”创建一个子弹,但是我没有得到这个值

我尝试了很多事情,无论我在互联网上发现了什么,但是我不知道为什么我没有得到这个价值

gatsby-node.js

module.exports.onCreateNode = ({ node, getNode, actions }) => {
  const { createNodeField } = actions
  if (node.internal.type === "MarkdownRemark") {
    console.log(node)
  }
}

gatsby-config.js

plugins: [
    {
      resolve: "gatsby-source-contentful",
      options: {
        spaceId: process.env.CONTENTFUL_SPACE_ID,
        accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
      },
    },
    `gatsby-plugin-sass`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: "src",
        path: `${__dirname}/src/`,
      },
    },

这里是输出:

{ id: '6b90d4a1-db96-5809-8900-60c21083d9ff',
  children: [],
  parent: '1ab34b1c-85e4-5f4c-a66e-561a4a95a886',
  internal:
   { content:
      'component is reusable by code which import anywhere and we can render anywhere in reactjs\r\n\r\nprops is just values which is passed from
parents\r\n\r\n',
     type: 'MarkdownRemark',
     contentDigest: '30b988e32ce51560a54006c3ec1829d0',
     owner: 'gatsby-transformer-remark' },
  frontmatter: { title: 'what is component and props', date: '19-02-2019' },
  excerpt: '',
  rawMarkdownBody:
   'component is reusable by code which import anywhere and we can render anywhere in reactjs\r\n\r\nprops is just values which is passed from
parents\r\n\r\n',
{ id: '5c79b3ff-4bcb-5a8b-bfa6-875f8c07a2b2',
  children: [],
  parent: 'c8cbb364-5455-5edc-bb73-5ffd0db1e9e7',
  internal:
   { content: '![DECENTROS](./decentros.jpg)',
     type: 'MarkdownRemark',
     contentDigest: '63c70587a28430a2df8b1ab1788863a6',
     owner: 'gatsby-transformer-remark' },
  frontmatter:
   { title: 'Decentros',
     description:
      'Decentros is the simple react web application.in which you can see the price of any cryptocurrency.in this web app i used api which is called
coinmarket which is really awesome.this is app is deployed on heroku.',
     link: 'http://decentros.herokuapp.com/',
     github: 'https://github.com/yashrajb/Decentros',
     download: '' },
  excerpt: '',
  rawMarkdownBody: '![DECENTROS](./decentros.jpg)',
  fileAbsolutePath:
{ id: '0f0f273f-3fae-51ae-9870-cafa98ec236b',
  children: [],
  parent: 'b5162009-6b12-5356-81e6-9cf9cd422c5e',
  internal:
   { content: '![DECENTROS](./devblog.jpg)',
     type: 'MarkdownRemark',
     contentDigest: '36579d03cdc3aae5e0e6ce2c4ba7e96c',
     owner: 'gatsby-transformer-remark' },
  frontmatter:
   { title: 'DevBlog',
     description:
      'Devblog is fullstack javascript web application.this is a multiuser blogging system.i created using node.js and mongodb.i also used Google Oauth
API and tinymce editor.',
     link: 'https://floating-everglades-10580.herokuapp.com/',
     github: 'https://github.com/yashrajb/DevBlog',
     download: '' },
  excerpt: '',
  rawMarkdownBody: '![DECENTROS](./devblog.jpg)',
  fileAbsolutePath:

我希望获得fileAbsolutePath值,这样我就可以塞子并且可以使用onCreatePages节点api

0 个答案:

没有答案