I would like to create an absolute link to files (images, downloads, ...) in my static
directory, so during development the link would be http://localhost/myimage.jpg
and once deployed it should be https://www.example.com/myimage.jpg
.
Is there an easy way (e.g. an environment variable etc.) to reference the current domain name in Gatsby?
I would like to achieve this behavior without changing any config files. A relative link is not an option in my case.
CodePudding user response:
The default behavior is what you described. Using the static folder, a structure like /static/myimage.jpg
will be referenced as https://somedomain.com/myimage.jpg
.
The same approach applies to PDF or any static asset you wish to make available.
Following that, a structure like: /static/images/myimage.jpg will become https://somedomain.com/images/myimage.jpg
.
Keep in mind that the static folder structure is "cloned" inside the public one once the site is built so everything inside will become public.
CodePudding user response:
Please visit gatsby image you will get your answer.