Skip to content

Commit a259ff8

Browse files
sampittkoLekoArts
andauthored
docs: add onCreateNode params and example (#27503)
Co-authored-by: LekoArts <[email protected]>
1 parent fb15745 commit a259ff8

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

packages/gatsby/index.d.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,34 @@ export interface GatsbyNode<
431431
* transform nodes created by other plugins should implement this API.
432432
*
433433
* See also the documentation for `createNode`
434-
* and [`createNodeField`](https://www.gatsbyjs.com/docs/actions/#createNodeField)
434+
* and [`createNodeField`](https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNodeField)
435+
* @param {object} $0
436+
* @param {object} $0.node A node object.
437+
* @param {object} $0.actions
438+
* @param {function} $0.actions.createNode Create a new node.
439+
* @param {function} $0.actions.createNodeField Extend another node. The new node field is placed under the fields key on the extended node object.
435440
* @example
436-
* exports.onCreateNode = ({ node, actions }) => {
437-
* const { createNode, createNodeField } = actions
438-
* // Transform the new node here and create a new node or
439-
* // create a new node field.
441+
* exports.onCreateNode = ({ node, getNode, actions }) => {
442+
* const { createNodeField } = actions
443+
*
444+
* if (node.internal.type === `MarkdownRemark`) {
445+
* const nodePath = node.fileAbsolutePath
446+
*
447+
* if (nodePath.match(/\/blog\//)) {
448+
* const postSlug = createFilePath({
449+
* node,
450+
* getNode,
451+
* basePath: `src/content`,
452+
* trailingSlash: true,
453+
* })
454+
*
455+
* createNodeField({
456+
* node,
457+
* name: `slug`,
458+
* value: `/blog/${postSlug}/`,
459+
* })
460+
* }
461+
* }
440462
* }
441463
*/
442464
onCreateNode?(

0 commit comments

Comments
 (0)