Giter VIP home page Giter VIP logo

next-static-og-images's Introduction

next-static-og-images

Generate static Open Graph images for Next.js at build time

Getting started

Installation

npm i -D next-static-og-images

or

yarn add -D next-static-og-images

Building Open Graph images

Add next-static-og-images to your postbuild script

{
  "build": "next build",
  "postbuild": "next-sitemap && next-static-og-images"
}

The sitemap.xml is used to identify pages that need Open Graph images generated. next-static-og-images works best with a sitemap generator like next-sitemap and assumes that a sitemap.xml file is created in the public directory.

Add og:image meta tags

Add the og:image tags to your _app.js or to reference the generated images.

<meta property="og:image" content="{`${host}/open-graph${asPath == "/" ? "/index" : asPath}.png`}" />
<meta property="og:image:alt" content="..." />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

Configuration options

property description type
saveLocation Directory where images should be saved. This directory will be cleared on each build. Default "./public/open-graph" string
sitemapFilename File path to the sitemap.xml location. Default "./public/sitemap.xml" string
screenshotType Specify screenshot type, can be either jpeg or png. Defaults to "png". string
width Page width used to create screenshot. Default 1200 number
height Page height used to create screenshot. Default 630 number
deviceScaleFactor Page device scale factor used to create screenshot. See devicePixelRatio for more info. Default 1 number
ogImageSelector If specified, screenshot will be based on the first instance a matching instance. If no elements match, the page will be used. Default undefined string
waitUntil When to consider navigation succeeded. See waitUntil for more info. Default "networkidle2" string

Image sizes will match the page height and width unless an image selector is used.

Contribution

PRs welcome

next-static-og-images's People

Contributors

adamhwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ltomlin

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.