node.js - Gatsby 节点 api 没有给出值“fileAbsolutePath”
问题描述
我在我的个人网站上工作,我在那个文件夹上创建了“blogpost”,我创建了“markdown”文件。所以我可以使用graphql抓取
我使用了 gatsby 节点 api“onCreateNode”。你可以在这里查看https://www.gatsbyjs.org/docs/node-apis/#onCreateNode
所以,在这里我想从“fileAbsolutePath”创建slug,但我没有得到这个值
我尝试了很多我在互联网上找到的东西,但我不知道为什么我没有得到这个价值
盖茨比-node.js
module.exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === "MarkdownRemark") {
console.log(node)
}
}
盖茨比-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 值,这样我就可以制作 slug 并且可以使用 onCreatePages 节点 api
解决方案
推荐阅读
- django - 如何通过在 Django 中使用表单设计将文件浏览器按钮更改为图像按钮
- python - xpath - IndexError:列表索引超出范围
- python - 如何替换掩码数组中的每个第 n 个空元素?
- javascript - 如何使用 ramda 表达式将项目从一个数组推送到另一个数组?
- sql - 在 sql 中考虑空值的子字符串替代方案
- html - 为什么图像的左右两侧会出现这条奇怪的闪烁垂直线?
- php - PhpStorm 代码分析:PHP 文件中的自定义“插值”分隔符
- python - 在 Python 中进行 Lexing 之后,如何用我自己的语言创建代码块?
- swift - SwiftUI - 没有使用 HTTP 基本身份验证的自动填充凭据
- java - Google 搜索无法识别符号