UNPKG

gatsby-source-prismic

Version:

Gatsby source plugin for building websites using Prismic as a data source

1 lines 1.59 kB
{"version":3,"file":"createCachedRemoteFileNode.cjs","sources":["../../../src/lib/createCachedRemoteFileNode.ts"],"sourcesContent":["import type { NodePluginArgs } from \"gatsby\";\nimport type { FileSystemNode } from \"gatsby-source-filesystem\";\nimport { createRemoteFileNode } from \"gatsby-source-filesystem\";\n\ntype CreateCachedRemoteFileNodeArgs = {\n\turl: string;\n\tgatsbyNodeArgs: NodePluginArgs;\n};\n\nexport const createCachedRemoteFileNode = async (\n\targs: CreateCachedRemoteFileNodeArgs,\n): Promise<FileSystemNode> => {\n\tconst cacheKey = `remote-file-node___${args.url}`;\n\tconst cachedFileNode: FileSystemNode = await args.gatsbyNodeArgs.cache.get(\n\t\tcacheKey,\n\t);\n\n\tif (cachedFileNode) {\n\t\targs.gatsbyNodeArgs.actions.touchNode(cachedFileNode);\n\n\t\treturn cachedFileNode;\n\t} else {\n\t\tconst fileNode = await createRemoteFileNode({\n\t\t\tcreateNode: args.gatsbyNodeArgs.actions.createNode,\n\t\t\tcreateNodeId: args.gatsbyNodeArgs.createNodeId,\n\t\t\turl: args.url,\n\t\t\tcache: args.gatsbyNodeArgs.cache,\n\t\t});\n\n\t\targs.gatsbyNodeArgs.cache.set(cacheKey, fileNode);\n\n\t\treturn fileNode;\n\t}\n};\n"],"names":["createRemoteFileNode"],"mappings":";;;AASa,MAAA,6BAA6B,OACzC,SAC4B;AACtB,QAAA,WAAW,sBAAsB,KAAK;AAC5C,QAAM,iBAAiC,MAAM,KAAK,eAAe,MAAM,IACtE,QAAQ;AAGT,MAAI,gBAAgB;AACd,SAAA,eAAe,QAAQ,UAAU,cAAc;AAE7C,WAAA;AAAA,EAAA,OACD;AACA,UAAA,WAAW,MAAMA,4CAAqB;AAAA,MAC3C,YAAY,KAAK,eAAe,QAAQ;AAAA,MACxC,cAAc,KAAK,eAAe;AAAA,MAClC,KAAK,KAAK;AAAA,MACV,OAAO,KAAK,eAAe;AAAA,IAAA,CAC3B;AAED,SAAK,eAAe,MAAM,IAAI,UAAU,QAAQ;AAEzC,WAAA;AAAA,EACP;AACF;;"}