Absolute Image Paths in Gatsby JSON
You can use createNodeField
on any type of nodes, not just markdown remark.
If you set up gatsby-config.js
like the following:
{ resolve: `gatsby-source-filesystem`, options: { path: `${__dirname}/content/meta`, <-- folder name is used to create node type name, i.e `MetaJson` name: `meta`, <-- doesn't affect json node's type name },},`gatsby-transformer-json`,
You can then transform them in gatsby-node.js
just like how you would do it with MarkdownRemark node.
exports.onCreateNode = ({ node, actions }) => { const { createNodeField } = actions if (node.internal.type === `MetaJson`) { const relativePath = ... createNodeField({ node, name: `foo`, value: relativePath, }) }}
You can also pass in additional options into gatsby-transformer-json
to have more fine grain control of the json nodes' internal type name.
And just like with markdown transformed by gatsby-transformer-remark
, jsons transformed by gatsby-transformer-json
also attach a child node onto its parent File node:
{ file( sourceInstanceName: { eq: "meta" } ) { dir childMetaJson { fields { foo } } }}