Skip to content

Commit

Permalink
fix(contentful): properly delete deleted entries and assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Rötsch committed Jun 6, 2018
1 parent 956a357 commit 3058f95
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 @@ -75,12 +75,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 = normalize.fixId(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 3058f95

Please sign in to comment.