implementing a static og image in Gatsby

I'm new in Gatsby and can't find a solution for this: I deployed a website which is just a "coming soon" landing page for now. I took a screenshot which i want to use as og-image for everything... It's now sitting in src/images but:

Upvotes: 1

Views: 1649

Answers (1)

Ferran Buireu
Ferran Buireu

Reputation: 29318

You hit the nail, the way to achieve what you want is to add it in your /static folder since you are not importing it as a component so the way to make the image available is this.

The URL of the image is the name of the image itself, with the same internal folder structure. As you can see in Gatsby documentation about static folder:

You can create a folder named static at the root of your project. Every file you put into that folder will be copied into the public folder. E.g. if you add a file named sun.jpg to the static folder, it’ll be copied to public/sun.jpg

In the previous case, the sun.jpg must be just one level inside /static. If you add another level, like /images/sun.jpg, your public URL will be https://example.com/images/sun.jpg.

So, in your case:

  {
    property: `og:image`,
    content: 'https://example.com/path_to_your_static_image.extension',
  },

Note: keep in mind that being a public URL, it won't work until you deploy your app and the image remain public

Upvotes: 3

Related Questions