ifiokjr / gatsby-plugin-next-seo

Gatsby Plugin Next SEO is a plug in that makes managing your SEO easier in Gatsby projects.
MIT License
195 stars 20 forks source link

openGraph new option: path #43

Open fcisio opened 3 years ago

fcisio commented 3 years ago

Description

Hi, when adding images to openGraph, right now we can use the url option.

It would be nice to allow for relative paths with a path option.

images: [
  {
    path: 'src/images/og-image-1.jpg',
    width: 800,
    height: 600,
    alt: 'Og Image Alt',
  },
  {
    path: path.resolve(__dirname, 'src/images/og-image-2.jpg'),
    width: 800,
    height: 600,
    alt: 'Og Image Alt 2',
  },
],

I know that it's currently possible by adding the domain used with the project. But manually adding the domain doesn't work well with multiple environments (staging.domain.com, domain.com, localhost, ...).

fcisio commented 3 years ago

I do have a workaround for this if anyone is interested:

// env.development
GATBSY_DOMAIN="http://localhost:8000"

// gatsby-config.js
require('dotenv').config({
  path: `.env.development`,
})

...

{
  url: `${process.env.GATBSY_DOMAIN}/images/socials.png`
}

Then set the env variable to the right domain when you deploy