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

gatsby-remark-copy-linked-files ignores copying files in sibling nodes when it finds one file included in the ignore ext array #5644

Closed
cupojoe opened this issue May 31, 2018 · 0 comments

Comments

@cupojoe
Copy link
Contributor

cupojoe commented May 31, 2018

Description

If you have a group of images as HTML, gatsby-remark-copy-linked-files will copy them until it finds one that is included in the ignore extensions list.

For instance:

<div>
  <figure>
    <img src="../media/pages/color-ui/dark-theme-do-3.jpg" />
    <figcaption class="ibm-type-b">White Overflow Menu on Gray 10 Card</figcaption>
  </figure>
  <figure>
    <img src="../media/pages/color-ui/dark-theme-dont-1.svg" />
    <figcaption class="ibm-type-b">Avoid use of midtones</figcaption>
  </figure>
</div>

In the previous block the plugin will find the jpg which is included in the ignore extensions array by default since it gets handled by remark images, and it will return from the entire div node instead of continuing to find the svg that need to be copied. The culprit to this issue is in these line:

if (options.ignoreFileExtensions.includes(ext)) {
return
}

Proposed solution:

Where it should check if the file is not in the list and take action and if it is in the list not return but continue the loop, like so:

for (let thisImg of imageRefs) {
  try {
    const ext = thisImg
          .attr(`src`)
          .split(`.`)
          .pop()
    if (!options.ignoreFileExtensions.includes(ext)) {
      generateImagesAndUpdateNode(thisImg, node)
    }
  } catch (err) {
    // Ignore
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant