Skip to content

Commit

Permalink
fix(contentful): properly delete deleted entries and assets (#5756)
Browse files Browse the repository at this point in the history
* fix(contentful): properly delete deleted entries and assets

fixes #5747

* remove duplicate id normalization
  • Loading branch information
axe312ger authored and pieh committed Jun 13, 2018
1 parent a09dfb3 commit cd9ae49
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ exports.sourceNodes = async (
// Remove deleted entries & assets.
// TODO figure out if entries referencing now deleted entries/assets
// are "updated" so will get the now deleted reference removed.

function deleteContentfulNode (node) {
const id = node.sys.id
const localizedIds = locales.map((locale) => normalize.makeId({ id, currentLocale: locale.code, defaultLocale }))
localizedIds.forEach(id => deleteNode(id, getNode(id)))
}

currentSyncData.deletedEntries
.map(e => e.sys.id)
.forEach(id => deleteNode(id, getNode(id)))
.forEach(deleteContentfulNode)
currentSyncData.deletedAssets
.map(e => e.sys.id)
.forEach(id => deleteNode(id, getNode(id)))
.forEach(deleteContentfulNode)

const existingNodes = getNodes().filter(
n => n.internal.owner === `gatsby-source-contentful`
Expand Down

0 comments on commit cd9ae49

Please sign in to comment.