New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-plugin-open-graph-images

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-open-graph-images

Build dynamic open-graph preview images for gatsby pages. Simply use react components to create SEO ready preview images for Twitter, Facebook, Linkedin, Google, and many more.

  • 0.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

gatsby-plugin-open-graph-images

Gatsby Plugin: Open Graph Images

Publish npm version

A Gatsby plugin to derive and generated Images for the Open Graph Protocol directly from React Components.

How to install

  1. yarn add gatsby-plugin-open-graph-images or npm i gatsby-plugin-open-graph-images
  2. Place the plugin in your main gatsby-config.js:
plugins: [`gatsby-plugin-open-graph-images`];

How to use

The creation of Open Graph images is done by createOpenGraphImage() within your gatsby-node.js file.

exports.createPages = async ({ actions }) => {
  const { createPage } = actions;

  const openGraphImage = createOpenGraphImage(createPage, {
    path: "/og-image/index.png",
    component: path.resolve(`src/templates/index.og-image.js`),
    size: {
      width: 400,
      height: 50,
    },
    waitCondition: "networkidle0",
    context: {
      description: "a image created with gatsby-plugin-open-graph-images",
    },
  });
};

You can than simply include your open-graph image within your page. For example by using react-helmet:

<Helmet>
  <meta property="og:image" content={domain + "/og-image/index.png"} />
  <meta property="og:image:width" content="400" />
  <meta property="og:image:width" content="50" />
</Helmet>

A more advanced usage of createOpenGraphImage() is described in this dev.to article.

Options

optiontypedescription
defaultSizeoptionalThe default size for the generated image if not explicitly specified.
default: { width: 1200, height: 630}
componentGenerationDiroptionalThe directory where the rendered gatsby components are temporarily stored, to be later saved as images
default: "__generated"

If you use plugins that iterate over your pages, like gatsby-plugin-sitemap, exclude the componentGenerationDir:

{
  resolve: `gatsby-plugin-sitemap`,
  options: {
    exclude: [`/__generated/*`],
  },
},

Keywords

FAQs

Package last updated on 02 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc