Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-source-filesystem): add optional name parameter to createRemoteFileNode #11054

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/gatsby-source-filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ exports.downloadMediaFiles = ({

The file node can then be queried using GraphQL. See an example of this in the [gatsby-source-wordpress README](/packages/gatsby-source-wordpress/#image-processing) where downloaded images are queried using [gatsby-transformer-sharp](/packages/gatsby-transformer-sharp/) to use in the component [gatsby-image](/packages/gatsby-image/).

#### Retrieving the remote file extension
#### Retrieving the remote file name and extension

The helper tries first to retrieve the file extension by parsing the url and the path provided (e.g. if the url is https://example.com/image.jpg, the extension will be inferred as `.jpg`). If the url does not contain an extension, we use the [`file-type`](https://www.npmjs.com/package/file-type) package to infer the file type. Finally, the extension _can_ be explicitly passed, like so:
The helper tries first to retrieve the file name and extension by parsing the url and the path provided (e.g. if the url is https://example.com/image.jpg, the extension will be inferred as `.jpg` and the name as `image`). If the url does not contain an extension, we use the [`file-type`](https://www.npmjs.com/package/file-type) package to infer the file type. Finally, the name and the extension _can_ be explicitly passed, like so:

```javascript
createRemoteFileNode({
Expand All @@ -241,5 +241,6 @@ createRemoteFileNode({
createNodeId,
// if necessary!
ext: ".jpg",
name: "image",
})
```
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ async function processRemoteNode({
auth = {},
createNodeId,
ext,
name,
}) {
// Ensure our cache directory exists.
const pluginCacheDir = path.join(
Expand All @@ -211,7 +212,9 @@ async function processRemoteNode({

// Create the temp and permanent file names for the url.
const digest = createHash(url)
const name = getRemoteFileName(url)
if (!name) {
name = getRemoteFileName(url)
}
if (!ext) {
ext = getRemoteFileExtension(url)
}
Expand Down Expand Up @@ -313,6 +316,7 @@ module.exports = ({
auth = {},
createNodeId,
ext = null,
name = null,
}) => {
// validation of the input
// without this it's notoriously easy to pass in the wrong `createNodeId`
Expand Down Expand Up @@ -355,6 +359,7 @@ module.exports = ({
createNodeId,
auth,
ext,
name,
})

fileDownloadPromise.then(() => bar.tick())
Expand Down