forked from graysonhicks/gatsby-plugin-remote-images
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(gatsby-node): Add support for traversing nested arrays
Before, if the objects holding your remote images were in an array, the `lodash .get` method could not traverse those arrays to target the correct objects. These changes add opt-in support for this functionality by extending `lodash .get`'s syntax to indicate where the arrays need to be traversed. Adding an array literal in the `path` option on the node holding the array, like `myArrayNode[].imageUrl`, triggers the logic to create image nodes for each object in `myArrayNode`. This does diverge from `lodash .get` syntax, but here were the considerations: * If we didn't have some explicit indication in the path, like `myArrayNode.imageUrl`, you would still have a value that was invalid to pass to `.get` as-is, but the code would internally have to hand-hold each node to see if it was an object or array before proceeding, essentially meaning you would have to reimplement `.get` and its safeguards. * The `[]` suffix is a pattern already found in other tools, like `TypeScript`, to indicate a node is an array, so it should be relatively recognizable to users * When no `[]` is supplied, the current logic reverts to the existing functionality, delegating object traversal entirely to `.get` There has also been interest to support [leaf nodes which contain an array of urls](graysonhicks#8). These changes don't add this support, but it should be possible to achieve with a bit of rework without having to rethink the entire approach.
- Loading branch information
1 parent
53b590a
commit 50331bd
Showing
2 changed files
with
128 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters