diff --git a/README.md b/README.md index 5d3ebb225d796..40e726d73a891 100644 --- a/README.md +++ b/README.md @@ -14,29 +14,31 @@ nodes from which you can query an HTML representation of the markdown. ```javascript // In your gatsby-config.js -plugins: [ - // You can have multiple instances of this plugin - // to read source nodes from different locations on your - // filesystem. - // - // The following sets up the Jekyll pattern of having a - // "pages" directory for Markdown files and a "data" directory - // for `.json`, `.yaml`, `.csv`. - { - resolve: `gatsby-source-filesystem`, - options: { - name: `pages`, - path: `${__dirname}/src/pages/`, +module.exports = { + plugins: [ + // You can have multiple instances of this plugin + // to read source nodes from different locations on your + // filesystem. + // + // The following sets up the Jekyll pattern of having a + // "pages" directory for Markdown files and a "data" directory + // for `.json`, `.yaml`, `.csv`. + { + resolve: `gatsby-source-filesystem`, + options: { + name: `pages`, + path: `${__dirname}/src/pages/`, + }, }, - }, - { - resolve: `gatsby-source-filesystem`, - options: { - name: `data`, - path: `${__dirname}/src/data/`, + { + resolve: `gatsby-source-filesystem`, + options: { + name: `data`, + path: `${__dirname}/src/data/`, + }, }, - }, -]; + ], +}; ``` ## How to query diff --git a/package.json b/package.json index 1384a150d0d15..f6296030ab754 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,11 @@ { "name": "gatsby-source-filesystem", - "version": "2.0.0-alpha.f20ac0ed", "description": "Gatsby plugin which parses files within a directory for further parsing by other plugins", - "license": "MIT", - "scripts": { - "build": "babel src --out-dir . --ignore **/__tests__/**", - "watch": "babel -w src --out-dir . --ignore **/__tests__/**", - "prepublish": "cross-env NODE_ENV=production npm run build" - }, - "keywords": [ - "gatsby", - "gatsby-plugin" - ], + "version": "2.0.0-alpha.f20ac0ed", "author": "Kyle Mathews ", + "bugs": { + "url": "https://github.com/gatsbyjs/gatsby/issues" + }, "dependencies": { "@babel/runtime": "^7.0.0-beta.38", "bluebird": "^3.5.0", @@ -29,5 +22,20 @@ "@babel/cli": "^7.0.0-beta.38", "@babel/core": "^7.0.0-beta.38", "cross-env": "^5.0.5" + }, + "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme", + "keywords": [ + "gatsby", + "gatsby-plugin" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/gatsbyjs/gatsby.git" + }, + "scripts": { + "build": "babel src --out-dir . --ignore __tests__", + "prepublish": "cross-env NODE_ENV=production npm run build", + "watch": "babel -w src --out-dir . --ignore __tests__" } } diff --git a/src/create-remote-file-node.js b/src/create-remote-file-node.js index a42ec71990740..9908bd4f7576b 100644 --- a/src/create-remote-file-node.js +++ b/src/create-remote-file-node.js @@ -7,8 +7,19 @@ const { isWebUri } = require(`valid-url`) const { createFileNode } = require(`./create-file-node`) const cacheId = url => `create-remote-file-node-${url}` -module.exports = ({ url, store, cache, createNode, auth = {} }) => - new Promise(async (resolve, reject) => { +/** + * Index of promises resolving to File node from remote url + */ +const processingCache = {} + +module.exports = ({ url, store, cache, createNode, auth = {} }) => { + // Check if we already requested node for this remote file + // and return stored promise if we did. + if (processingCache[url]) { + return processingCache[url] + } + + return (processingCache[url] = new Promise(async (resolve, reject) => { if (!url || isWebUri(url) === undefined) { resolve() return @@ -99,4 +110,5 @@ module.exports = ({ url, store, cache, createNode, auth = {} }) => resolve(fileNode) }) }) - }) + })) +} diff --git a/src/extend-file-node.js b/src/extend-file-node.js index 99bf81a29a2ad..38d07c0dd3e98 100644 --- a/src/extend-file-node.js +++ b/src/extend-file-node.js @@ -11,6 +11,7 @@ module.exports = ({ type, getNodeAndSavePathDependency, pathPrefix = `` }) => { publicURL: { type: GraphQLString, args: {}, + description: `Copy file to static directory and return public url to it`, resolve: (file, fieldArgs, context) => { const details = getNodeAndSavePathDependency(file.id, context.path) const fileName = `${file.name}-${file.internal.contentDigest}${