contentful-labs / starter-gatsby-blog

Gatsby starter for a Contentful project from the community.
https://contentful.github.io/starter-gatsby-blog/
MIT License
195 stars 199 forks source link

Load images locally and not through CDN #143

Open ghost opened 3 years ago

ghost commented 3 years ago

Is it possible to setup this so images from body posts are loaded locally without contentful CDN?

ghost commented 3 years ago

I asked this question on Gatsby discussion but no one answered https://github.com/gatsbyjs/gatsby/discussions/28104

axe312ger commented 3 years ago

We do not recommend to work around our CDNs and directly use our Image API. Thats what the gatsby plugin does.

Whats your reason for doing this?

You still can do it: (I assume you use Markdown)

  1. First enable downloadLocal in gatsby-source-contentful
  2. create a remark plugin similar to https://www.gatsbyjs.com/plugins/gatsby-remark-images-contentful/ that rewrites the image tag src to your local path
ghost commented 3 years ago

@axe312ger Thanks, have you seen an example in the past? I am wondering if anyone has done something similar to this, I dont think I can write a plugin yet :( , I enabled downloadLocal but none of the images are downloaded.

axe312ger commented 3 years ago

No sorry, I did not write a remark plugin yet :(

Try:

https://www.gatsbyjs.com/tutorial/remark-plugin-tutorial/ https://github.com/remarkjs/remark/blob/main/doc/plugins.md