From 21707b5ec6b43622900472824cea122d79fe7568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Pito=C5=88=C3=A1k?= Date: Fri, 16 Oct 2020 21:14:13 +0200 Subject: [PATCH 1/3] docs: add onCreateNode params and example --- packages/gatsby/index.d.ts | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 5337a4d438fc0..eab73c4e74edf 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -293,12 +293,33 @@ export interface GatsbyNode { * * See also the documentation for `createNode` * and [`createNodeField`](https://www.gatsbyjs.org/docs/actions/#createNodeField) - * @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. - * } + * @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. + * exports.onCreateNode = ({ node, getNode, actions }) => { + * const { createNodeField } = actions; + * + * if (node.internal.type === `Mdx`) { + * const nodePath = node.fileAbsolutePath; + * + * if (nodePath.match(/\/blog\//)) { + * const postSlug = createFilePath({ + * node, + * getNode, + * basePath: `src/content`, + * trailingSlash: true, + * }); + * + * createNodeField({ + * node, + * name: `slug`, + * value: polishSlug(`/blog/${postSlug}/`), + * }); + * } + * } + * } */ onCreateNode?( args: CreateNodeArgs, From b5003cddf356288086b472ef80d0ec6aa437ff3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Pito=C5=88=C3=A1k?= Date: Fri, 16 Oct 2020 21:25:37 +0200 Subject: [PATCH 2/3] Add missing @example annotation --- packages/gatsby/index.d.ts | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index eab73c4e74edf..45f1e6f77949e 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -293,33 +293,34 @@ export interface GatsbyNode { * * See also the documentation for `createNode` * and [`createNodeField`](https://www.gatsbyjs.org/docs/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. - * exports.onCreateNode = ({ node, getNode, actions }) => { - * const { createNodeField } = actions; - * - * if (node.internal.type === `Mdx`) { - * const nodePath = node.fileAbsolutePath; - * - * if (nodePath.match(/\/blog\//)) { - * const postSlug = createFilePath({ - * node, - * getNode, - * basePath: `src/content`, - * trailingSlash: true, - * }); - * - * createNodeField({ - * node, - * name: `slug`, - * value: polishSlug(`/blog/${postSlug}/`), - * }); - * } - * } - * } + * @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, getNode, actions }) => { + * const { createNodeField } = actions; + * + * if (node.internal.type === `Mdx`) { + * const nodePath = node.fileAbsolutePath; + * + * if (nodePath.match(/\/blog\//)) { + * const postSlug = createFilePath({ + * node, + * getNode, + * basePath: `src/content`, + * trailingSlash: true, + * }); + * + * createNodeField({ + * node, + * name: `slug`, + * value: polishSlug(`/blog/${postSlug}/`), + * }); + * } + * } + * } */ onCreateNode?( args: CreateNodeArgs, From d770551050791accf0289aacd44834fbe29ecb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Pito=C5=88=C3=A1k?= Date: Mon, 19 Oct 2020 10:01:22 +0200 Subject: [PATCH 3/3] Remove polishSlug --- packages/gatsby/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 45f1e6f77949e..432d253620b3e 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -316,7 +316,7 @@ export interface GatsbyNode { * createNodeField({ * node, * name: `slug`, - * value: polishSlug(`/blog/${postSlug}/`), + * value: `/blog/${postSlug}/`, * }); * } * }