Giter Club home page Giter Club logo

gatsby-plugin-open-graph-images's Introduction

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

option type description
defaultSize optional The default size for the generated image if not explicitly specified.
default: { width: 1200, height: 630}
componentGenerationDir optional The 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/*`],
  },
},

gatsby-plugin-open-graph-images's People

Contributors

duffleit avatar dscush avatar riywo avatar splatte avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.