Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Fix PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: soupette <[email protected]>
  • Loading branch information
soupette committed Feb 9, 2022
1 parent a1cd966 commit f50051e
Showing 1 changed file with 27 additions and 50 deletions.
77 changes: 27 additions & 50 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

import { fetchStrapiContentTypes, fetchEntities, fetchEntity } from './fetch';
import { downloadFile, downloadMediaFiles } from './download-media-files';
import { downloadMediaFiles } from './download-media-files';
import {
buildMapFromNodes,
buildNodesToRemoveMap,
Expand Down Expand Up @@ -139,60 +139,37 @@ exports.sourceNodes = async (
for (let i = 0; i < endpoints.length; i++) {
const { uid } = endpoints[i];

if (uid === 'plugin::upload.file') {
for (let file of data[i]) {
file.strapi_id = file.id;
const fileNodeId = await downloadFile(file, ctx);

file[`localFile___NODE`] = fileNodeId;
const nodeType = makeParentNodeName(ctx.schemas, uid);

await actions.createNode({
...file,
id: createNodeId(`${nodeType}-${file.id}`),
parent: null,
children: [],
internal: {
type: nodeType,
content: JSON.stringify(file),
contentDigest: createContentDigest(file),
},
});
}
} else {
await downloadMediaFiles(data[i], ctx, uid);
await downloadMediaFiles(data[i], ctx, uid);

for (let entity of data[i]) {
const nodes = createNodes(entity, ctx, uid);
for (let entity of data[i]) {
const nodes = createNodes(entity, ctx, uid);

await Promise.all(nodes.map((n) => actions.createNode(n)));
await Promise.all(nodes.map((n) => actions.createNode(n)));

const nodeType = makeParentNodeName(ctx.schemas, uid);
const nodeType = makeParentNodeName(ctx.schemas, uid);

const mainEntryNode = nodes.find((n) => {
return n && n.strapi_id === entity.id && n.internal.type === nodeType;
});
const mainEntryNode = nodes.find((n) => {
return n && n.strapi_id === entity.id && n.internal.type === nodeType;
});

const isPreview = process.env.GATSBY_IS_PREVIEW === `true`;
const createNodeManifestIsSupported = typeof unstable_createNodeManifest === `function`;
const shouldCreateNodeManifest =
isPreview && createNodeManifestIsSupported && mainEntryNode;

if (shouldCreateNodeManifest) {
const updatedAt = entity.updatedAt;
const manifestId = `${uid}-${entity.id}-${updatedAt}`;

actions.unstable_createNodeManifest({
manifestId,
node: mainEntryNode,
updatedAtUTC: updatedAt,
});
} else if (isPreview && !createNodeManifestIsSupported && !warnOnceForNoSupport) {
console.warn(
`gatsby-source-strapi: 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.`
);
warnOnceForNoSupport = true;
}
const isPreview = process.env.GATSBY_IS_PREVIEW === `true`;
const createNodeManifestIsSupported = typeof unstable_createNodeManifest === `function`;
const shouldCreateNodeManifest = isPreview && createNodeManifestIsSupported && mainEntryNode;

if (shouldCreateNodeManifest) {
const updatedAt = entity.updatedAt;
const manifestId = `${uid}-${entity.id}-${updatedAt}`;

actions.unstable_createNodeManifest({
manifestId,
node: mainEntryNode,
updatedAtUTC: updatedAt,
});
} else if (isPreview && !createNodeManifestIsSupported && !warnOnceForNoSupport) {
console.warn(
`gatsby-source-strapi: 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.`
);
warnOnceForNoSupport = true;
}
}
}
Expand Down

0 comments on commit f50051e

Please sign in to comment.