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

Static assets not prefixed #13

Closed
i001962 opened this issue May 22, 2019 · 8 comments
Closed

Static assets not prefixed #13

i001962 opened this issue May 22, 2019 · 8 comments

Comments

@i001962
Copy link

i001962 commented May 22, 2019

Looks like static images aren't getting prefixed.

Could it be as simple as adding static directory to gatsby-node.js line 74

const relativizeMiscAssetFiles = async () => {
    // Replaces all /__GATSBY_IPFS_PATH_PREFIX__/ strings to standard relative paths
    const paths = await globby(['public/**/*', '!public/**/*.html', '!public/**/*.js']);

@satazor
Copy link
Contributor

satazor commented May 22, 2019

I don't think the static folder needs to be processed unless there are HTML or JS files there referencing images to the same static folder.

The issue is that some static files, such as images, are being referenced within the src/ code of projects but they aren't being handled by the plugin:

// https://www.gatsbyjs.org/docs/static-folder/#referencing-your-static-asset
render() {
  // Note: this is an escape hatch and should be used sparingly!
  // Normally we recommend using `import` for getting asset URLs
  // as described in the “Importing Assets Directly Into Files” page.
  return <img src={'logo.png'} alt="Logo" />;
}

How can this plugin detect and parse these scenarios reliably without false positives? With __GATSBY_IPFS_PATH_PREFIX__ is easy but it's not added in these situations since we haven't imported them. One solution would be to do __GATSBY_IPFS_PATH_PREFIX__/logo.png but feels strange to have that in the source code.

@i001962
Copy link
Author

i001962 commented May 22, 2019

Feel free to close this then. I had installed it on a starter that must have been using the escape hatch.

@satazor
Copy link
Contributor

satazor commented May 22, 2019

@i001962 While it's an escape hatch, there are valid use cases for it. I would be better to have a solution when we need this, even if it's just a note in the README asking them to prefix with __GATSBY_IPFS_PATH_PREFIX__. Can you test if prefixing with __GATSBY_IPFS_PATH_PREFIX__ when you referencing them works? If so, I would love a PR that adds this note into the README ❤

@i001962
Copy link
Author

i001962 commented May 23, 2019

@satazor ok will do but please confirm that something like this is what you are suggesting:

// https://www.gatsbyjs.org/docs/static-folder/#referencing-your-static-asset
render() {
  // Note: this is an escape hatch and should be used sparingly!
  // Normally we recommend using `import` for getting asset URLs
  // as described in the “Importing Assets Directly Into Files” page.
  return <img src={'__GATSBY_IPFS_PATH_PREFIX__logo.png'} alt="Logo" />;
}

@satazor
Copy link
Contributor

satazor commented May 23, 2019

Yep that’s it, I think you are missing a trailing slash.

@i001962
Copy link
Author

i001962 commented May 23, 2019

@satazor that's why I was asking. 😆

@satazor
Copy link
Contributor

satazor commented May 23, 2019

@i001962 did the workaround solve the issue? Since you made a PR adding a note to the readme, I suppose it did?

@i001962
Copy link
Author

i001962 commented May 23, 2019

Turns out static assets were not the issue. I will close this issue now as I have restated the issue in issue #14

@i001962 i001962 closed this as completed May 23, 2019
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

2 participants