Skip to content

Commit

Permalink
[gatsby-source-wordpress] Treat wp settings as a known type for inclu…
Browse files Browse the repository at this point in the history
…sion (#5708)

* Append wordpress_id to wp settings to prevent exclusion

Signed-off-by: Adam Mould <adamwmould@gmail.com>

* Treat wp settings as a known type

Signed-off-by: Adam Mould <adamwmould@gmail.com>

* Comments to explain normalize functions

Signed-off-by: Adam Mould <adamwmould@gmail.com>
  • Loading branch information
Adam-Mould authored and pieh committed Jun 5, 2018
1 parent 0e4cfd6 commit 050b6ef
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/gatsby-source-wordpress/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,20 @@ exports.liftRenderedField = entities =>
})

// Exclude entities of unknown shape
// Assume all entities contain a wordpress_id, except for whitelisted type wp_settings
exports.excludeUnknownEntities = entities =>
entities.filter(e => e.wordpress_id) // Excluding entities without ID
entities.filter(e => e.wordpress_id || e.__type === `wordpress__wp_settings`) // Excluding entities without ID, or WP Settings

// Create node ID from known entities
// excludeUnknownEntities whitelisted types don't contain a wordpress_id
// we create the node ID based upon type if the wordpress_id doesn't exist
exports.createGatsbyIds = (createNodeId, entities) =>
entities.map(e => {
e.id = createNodeId(`${e.__type}-${e.wordpress_id.toString()}`)
if (e.wordpress_id) {
e.id = createNodeId(`${e.__type}-${e.wordpress_id.toString()}`)
} else {
e.id = createNodeId(e.__type)
}
return e
})

Expand Down

0 comments on commit 050b6ef

Please sign in to comment.