diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 80c8fc6a5d2..73208635d8b 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', + mapEntryToContext: (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'), diff --git a/packages/gatsby/src/gatsby-node.js b/packages/gatsby/src/gatsby-node.js index 04812bd486b..962a077da2f 100644 --- a/packages/gatsby/src/gatsby-node.js +++ b/packages/gatsby/src/gatsby-node.js @@ -132,12 +132,19 @@ const createPagesAsync = async (config, createPage, graphql, models, offsets) => } entries.forEach(entry => { if (entry.content.data.url && entry.content.published === `published`) { + + let mappedProps = {}; + if (config.mapEntryToContext) { + mappedProps = config.mapEntryToContext(entry); + } + createPage({ path: entry.content.data.url, component, - ...(config.globalContext && { - context: config.globalContext, - }), + context: { + ...(config.globalContext || {}), + ...mappedProps + } }); } });