Skip to content

Commit 3dc7629

Browse files
authored
feat(gatsby-source-drupal): Add node manifest support for previews (#33683)
* Drupal plugin: Add node manifest support.
1 parent 09effad commit 3dc7629

File tree

1 file changed

+39
-1
lines changed
  • packages/gatsby-source-drupal/src

1 file changed

+39
-1
lines changed

packages/gatsby-source-drupal/src/utils.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,20 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
272272
`
273273
)
274274

275-
const { createNode } = actions
275+
const { createNode, unstable_createNodeManifest } = actions
276276

277277
const newNode = nodeFromData(
278278
nodeToUpdate,
279279
createNodeId,
280280
pluginOptions.entityReferenceRevisions
281281
)
282282

283+
drupalCreateNodeManifest({
284+
attributes: nodeToUpdate.attributes,
285+
gatsbyNode: newNode,
286+
unstable_createNodeManifest,
287+
})
288+
283289
const nodesToUpdate = [newNode]
284290

285291
const oldNodeReferencedNodes = referencedNodesLookup.get(newNode.id)
@@ -369,5 +375,37 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
369375
}
370376
}
371377

378+
let hasLoggedContentSyncWarning = false
379+
/**
380+
* This fn creates node manifests which are used for Gatsby Cloud Previews via the Content Sync API/feature.
381+
* Content Sync routes a user from Drupal to a page created from the entry data they're interested in previewing.
382+
*/
383+
function drupalCreateNodeManifest({
384+
attributes,
385+
gatsbyNode,
386+
unstable_createNodeManifest,
387+
}) {
388+
const isPreview =
389+
(process.env.NODE_ENV === `development` &&
390+
process.env.ENABLE_GATSBY_REFRESH_ENDPOINT) ||
391+
process.env.GATSBY_IS_PREVIEW === `true`
392+
393+
if (typeof unstable_createNodeManifest === `function` && isPreview) {
394+
const manifestId = `${attributes.drupal_internal__nid}-${attributes.revision_timestamp}`
395+
396+
console.info(`Drupal: Creating node manifest with id ${manifestId}`)
397+
398+
unstable_createNodeManifest({
399+
manifestId,
400+
node: gatsbyNode,
401+
})
402+
} else if (!hasLoggedContentSyncWarning) {
403+
hasLoggedContentSyncWarning = true
404+
console.warn(
405+
`Drupal: Your version of Gatsby core doesn't support Content Sync (via the unstable_createNodeManifest action). Please upgrade to the latest version to use Content Sync in your site.`
406+
)
407+
}
408+
}
409+
372410
exports.handleWebhookUpdate = handleWebhookUpdate
373411
exports.handleDeletedNode = handleDeletedNode

0 commit comments

Comments
 (0)