d4rekanguok / gatsby-remark-images-anywhere

Handle images with relative, absolute & remote path for gatsby-transformer-remark & gatsby-plugin-mdx
MIT License
22 stars 8 forks source link

allow users to whitelist protocol relative url #13

Open d4rekanguok opened 4 years ago

d4rekanguok commented 4 years ago

Apparently contentful inline asset url is just //images.cdn... instead of https://..., so the url fell thru. Kinda weird.

Gatsby provides an official plugin to handle images in contentful, but it's still handy to make this plugin work with those assets as well.

d4rekanguok commented 4 years ago

So this is called 'protocol relative url', which now has been declared an anti-pattern source.

The gatsby contentful remark image plugin does this:

https://github.com/gatsbyjs/gatsby/blob/6f422b07799d529d0847e030ff9e1acf1f71e89f/packages/gatsby-remark-images-contentful/src/index.js#L48-L50

...and I need this use case now, so let's just copy this over... and remove it when contenful stops sending these urls.

d4rekanguok commented 4 years ago

Actually, let user add the whitelist in their config. We don't need to store a list internally like this

benedictjohannes commented 4 years ago

Hi, I've checked that this plugin hard codes the whitelisted domains a certain domain, ['images.ctfassets.net'] in src/relative-protocol-whitelist.ts.

While #14 helps with Contentful, there's still no way for users to specify whitelisted domain.

My idea in implementing is to add relativeImageProtocol key into plugin configuration and have this merged into predefined whitelist.

Let me know if I should help & open PR for this, if work on this has not been started.

d4rekanguok commented 4 years ago

Hi @benedictjohannes, thank you for your interests in this plugin! I would gladly take a PR that address this.