From 4a14209dc0cc923dfc9b9ee5b5d7d6d092fb88b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Aparicio=20Mart=C3=ADn?= <40391767+apaniel90vp@users.noreply.github.com> Date: Sat, 31 Oct 2020 13:02:37 +0100 Subject: [PATCH 1/5] add map to gatsby config --- packages/gatsby/src/gatsby-node.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/src/gatsby-node.js b/packages/gatsby/src/gatsby-node.js index 04812bd486b..5700946d35b 100644 --- a/packages/gatsby/src/gatsby-node.js +++ b/packages/gatsby/src/gatsby-node.js @@ -129,15 +129,19 @@ const createPagesAsync = async (config, createPage, graphql, models, offsets) => } if (config.filter) { entries = entries.filter(config.filter); - } + } entries.forEach(entry => { if (entry.content.data.url && entry.content.published === `published`) { + + let mappedProps = {} + if (config.mapEntryToGatsbyConfig) { + mappedProps = config.mapEntryToGatsbyConfig(entry) + } + createPage({ path: entry.content.data.url, component, - ...(config.globalContext && { - context: config.globalContext, - }), + context: {...(config.globalContext || {}), ...mappedProps} }); } }); From 86c3c06c67a737bfcdcc00bb8d8c2310da14bf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Aparicio=20Mart=C3=ADn?= <40391767+apaniel90vp@users.noreply.github.com> Date: Sat, 31 Oct 2020 13:06:16 +0100 Subject: [PATCH 2/5] update readme with map callback --- packages/gatsby/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 80c8fc6a5d2..30cbac35810 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -22,6 +22,13 @@ module.exports = { options: { // public API Key publicAPIKey: 'MY_PUBLIC_API_KEY', + mapEntryToGatsbyConfig: (entry) => { + return { + property: entry.data.property, + anotherProperty: entry.data.whatever, + ... + }; + } templates: { // `page` can be any model of choice, camelCased page: path.resolve('templates/my-page.tsx'), From a2c123b543de969c1a111614a3e3ea41ba81ecff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Aparicio=20Mart=C3=ADn?= <40391767+apaniel90vp@users.noreply.github.com> Date: Mon, 2 Nov 2020 18:00:18 +0100 Subject: [PATCH 3/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Armando Pérez Marqués --- packages/gatsby/README.md | 2 +- packages/gatsby/src/gatsby-node.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 30cbac35810..945c4ca0fa8 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -26,7 +26,7 @@ module.exports = { return { property: entry.data.property, anotherProperty: entry.data.whatever, - ... + /* ... */ }; } templates: { diff --git a/packages/gatsby/src/gatsby-node.js b/packages/gatsby/src/gatsby-node.js index 5700946d35b..96174e70063 100644 --- a/packages/gatsby/src/gatsby-node.js +++ b/packages/gatsby/src/gatsby-node.js @@ -129,19 +129,22 @@ const createPagesAsync = async (config, createPage, graphql, models, offsets) => } if (config.filter) { entries = entries.filter(config.filter); - } + } entries.forEach(entry => { if (entry.content.data.url && entry.content.published === `published`) { - let mappedProps = {} + let mappedProps = {}; if (config.mapEntryToGatsbyConfig) { - mappedProps = config.mapEntryToGatsbyConfig(entry) + mappedProps = config.mapEntryToGatsbyConfig(entry); } createPage({ path: entry.content.data.url, component, - context: {...(config.globalContext || {}), ...mappedProps} + context: { + ...(config.globalContext || {}), + ...mappedProps. + } }); } }); From 950b9fef7c7f3b6697eba0a2149e941110853f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Aparicio=20Mart=C3=ADn?= <40391767+apaniel90vp@users.noreply.github.com> Date: Mon, 2 Nov 2020 23:00:37 +0100 Subject: [PATCH 4/5] Apply suggestions from code review --- packages/gatsby/README.md | 2 +- packages/gatsby/src/gatsby-node.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 945c4ca0fa8..73208635d8b 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -22,7 +22,7 @@ module.exports = { options: { // public API Key publicAPIKey: 'MY_PUBLIC_API_KEY', - mapEntryToGatsbyConfig: (entry) => { + mapEntryToContext: (entry) => { return { property: entry.data.property, anotherProperty: entry.data.whatever, diff --git a/packages/gatsby/src/gatsby-node.js b/packages/gatsby/src/gatsby-node.js index 96174e70063..278031e43e7 100644 --- a/packages/gatsby/src/gatsby-node.js +++ b/packages/gatsby/src/gatsby-node.js @@ -134,8 +134,8 @@ const createPagesAsync = async (config, createPage, graphql, models, offsets) => if (entry.content.data.url && entry.content.published === `published`) { let mappedProps = {}; - if (config.mapEntryToGatsbyConfig) { - mappedProps = config.mapEntryToGatsbyConfig(entry); + if (config.mapEntryToContext) { + mappedProps = config.mapEntryToContext(entry); } createPage({ From 180560d087ba7fcb54865e2eb9c0c0911fbf8f73 Mon Sep 17 00:00:00 2001 From: Aziz Abbas Date: Mon, 2 Nov 2020 14:37:34 -0800 Subject: [PATCH 5/5] Update gatsby-node.js --- packages/gatsby/src/gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/gatsby-node.js b/packages/gatsby/src/gatsby-node.js index 278031e43e7..962a077da2f 100644 --- a/packages/gatsby/src/gatsby-node.js +++ b/packages/gatsby/src/gatsby-node.js @@ -143,7 +143,7 @@ const createPagesAsync = async (config, createPage, graphql, models, offsets) => component, context: { ...(config.globalContext || {}), - ...mappedProps. + ...mappedProps } }); }