Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some context to function description comment so it's easier for future contributors? That we assume that all entities need ids except for whitelisted types (currently just settings)

// 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