Skip to content

Commit

Permalink
[gatsby-source-wordpress] add option for custom normalizer (gatsbyjs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Fetten committed May 30, 2018
1 parent 42ebe8a commit e0471ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/gatsby-source-wordpress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ plugins: [
// Example: `["/*/*/comments", "/yoast/**"]` will exclude routes ending in `comments` and
// all routes that begin with `yoast` from fetch.
excludedRoutes: ["/*/*/comments", "/yoast/**"],
// use a custom normalizer which is applied after the built-in ones.
normalizer: function({ entities }) {
return entities;
},
},
},
];
Expand Down
29 changes: 29 additions & 0 deletions packages/gatsby-source-wordpress/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let _auth
let _perPage
let _concurrentRequests
let _excludedRoutes
let _normalizer

exports.sourceNodes = async (
{ boundActionCreators, getNode, store, cache, createNodeId },
Expand All @@ -32,6 +33,7 @@ exports.sourceNodes = async (
searchAndReplaceContentUrls = {},
concurrentRequests = 10,
excludedRoutes = [],
normalizer,
}
) => {
const { createNode, touchNode } = boundActionCreators
Expand All @@ -43,6 +45,7 @@ exports.sourceNodes = async (
_perPage = perPage
_concurrentRequests = concurrentRequests
_excludedRoutes = excludedRoutes
_normalizer = normalizer

let entities = await fetch({
baseUrl,
Expand Down Expand Up @@ -112,6 +115,32 @@ exports.sourceNodes = async (
searchAndReplaceContentUrls,
})

// apply custom normalizer
if (typeof _normalizer === `function`) {
entities = _normalizer({
entities,
store,
cache,
createNode,
createNodeId,
touchNode,
getNode,
typePrefix,
refactoredEntityTypes,
baseUrl,
protocol,
_siteURL,
hostingWPCOM,
useACF,
auth,
verboseOutput,
perPage,
searchAndReplaceContentUrls,
concurrentRequests,
excludedRoutes,
})
}

// creates nodes for each entry
normalize.createNodesFromEntities({ entities, createNode })

Expand Down

0 comments on commit e0471ae

Please sign in to comment.