0.2.1 • Published 3 months ago

next-static-og-images v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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

propertydescriptiontype
saveLocationDirectory where images should be saved. This directory will be cleared on each build. Default "./public/open-graph"string
sitemapFilenameFile path to the sitemap.xml location. Default "./public/sitemap.xml"string
screenshotTypeSpecify screenshot type, can be either jpeg or png. Defaults to "png".string
widthPage width used to create screenshot. Default 1200number
heightPage height used to create screenshot. Default 630number
deviceScaleFactorPage device scale factor used to create screenshot. See devicePixelRatio for more info. Default 1number
ogImageSelectorIf specified, screenshot will be based on the first instance a matching instance. If no elements match, the page will be used. Default undefinedstring
waitUntilWhen 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

0.2.1

3 months ago

0.2.0

11 months ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago