Skip to content

Commit

Permalink
docs: add onCreateNode params and example (#27503)
Browse files Browse the repository at this point in the history
Co-authored-by: LekoArts <lekoarts@gmail.com>
  • Loading branch information
sampittko and LekoArts committed Nov 23, 2022
1 parent fb15745 commit a259ff8
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions packages/gatsby/index.d.ts
Expand Up @@ -431,12 +431,34 @@ export interface GatsbyNode<
* transform nodes created by other plugins should implement this API.
*
* See also the documentation for `createNode`
* and [`createNodeField`](https://www.gatsbyjs.com/docs/actions/#createNodeField)
* and [`createNodeField`](https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNodeField)
* @param {object} $0
* @param {object} $0.node A node object.
* @param {object} $0.actions
* @param {function} $0.actions.createNode Create a new node.
* @param {function} $0.actions.createNodeField Extend another node. The new node field is placed under the fields key on the extended node object.
* @example
* exports.onCreateNode = ({ node, actions }) => {
* const { createNode, createNodeField } = actions
* // Transform the new node here and create a new node or
* // create a new node field.
* exports.onCreateNode = ({ node, getNode, actions }) => {
* const { createNodeField } = actions
*
* if (node.internal.type === `MarkdownRemark`) {
* const nodePath = node.fileAbsolutePath
*
* if (nodePath.match(/\/blog\//)) {
* const postSlug = createFilePath({
* node,
* getNode,
* basePath: `src/content`,
* trailingSlash: true,
* })
*
* createNodeField({
* node,
* name: `slug`,
* value: `/blog/${postSlug}/`,
* })
* }
* }
* }
*/
onCreateNode?(
Expand Down

0 comments on commit a259ff8

Please sign in to comment.