# gatsby-plugin-printer

> ## Node API

Latest version **1.1.1** (published 2020-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-plugin-printer
pnpm add gatsby-plugin-printer
yarn add gatsby-plugin-printer
bun add gatsby-plugin-printer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-04-27 |
| First published | 2019-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Chris Biscardi |
| Maintainers | biscarch |

## Links

- npm: https://www.npmjs.com/package/gatsby-plugin-printer
- Repository: https://github.com/ChristopherBiscardi/gatsby-plugins
- Homepage: https://github.com/ChristopherBiscardi/gatsby-plugins#readme
- Issues: https://github.com/ChristopherBiscardi/gatsby-plugins/issues
- npm.io page: https://npm.io/package/gatsby-plugin-printer

## Dependencies (11)

- [rollup](https://npm.io/package/rollup.md) 1.23.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [puppeteer](https://npm.io/package/puppeteer.md) ^2.0.0
- [babel-plugin-preval](https://npm.io/package/babel-plugin-preval.md) ^3.0.1
- [rollup-plugin-babel](https://npm.io/package/rollup-plugin-babel.md) ^4.3.3
- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) ^0.9.1
- [rollup-plugin-replace](https://npm.io/package/rollup-plugin-replace.md) ^2.2.0
- [rollup-plugin-commonjs](https://npm.io/package/rollup-plugin-commonjs.md) ^10.0.1
- [rollup-plugin-node-globals](https://npm.io/package/rollup-plugin-node-globals.md) ^1.4.0
- [rollup-plugin-node-resolve](https://npm.io/package/rollup-plugin-node-resolve.md) ^5.2.0
- [rollup-plugin-node-builtins](https://npm.io/package/rollup-plugin-node-builtins.md) ^2.1.2

## Recent versions

- 1.1.1 (latest) — 2020-04-27
- 1.1.0 — 2019-11-08
- 1.0.8 — 2019-11-03
- 1.0.7 — 2019-10-25
- 1.0.6 — 2019-10-18
- 1.0.5 — 2019-10-04
- 1.0.4 — 2019-09-26
- 1.0.3 — 2019-09-01
- 1.0.2 — 2019-08-30
- 1.0.1 — 2019-08-30
- 1.0.0 — 2019-08-30

## README

# gatsby-plugin-printer

## Node API

This is a declarative API that lets the library control batching, caching, etc. Creating `Printer` nodes via this API doesn't give you a `fileName` back, so you would have to specify one.

```js
const { createPrinterNode } = require(`gatsby-plugin-printer`);

exports.onCreateNode = ({ actions, node }) => {
  if (node.internal.type === "Mdx") {
    // createPrinterNode creates an object that can be passed in
    // to `createNode`
    createPrinterNode({
      id: node.id,
      // fileName is something you can use in opengraph images, etc
      fileName: slugify(node.title),
      // renderDir is relative to `public` by default
      outputDir: "blog-post-images",
      // data gets passed directly to your react component
      data: node,
      // the component to use for rendering. Will get batched with
      // other nodes that use the same component
      component: require.resolve("./src/printer-components/blog-post.js")
    });
  }
};
```

## Manual control

You can also import and use `runScreenshots` but note that you will have to control batching, etc yourself.

```js
exports.onPostBuild = ({graphql}) => {

  const data = await graphql(`
    {
      allBlogPost {
        nodes {
          title
        }
      }
    }
  `).then(r => {
    if (r.errors) {
      reporter.error(r.errors.join(`, `));
    }
    return r.data;
  });

const titles = data.allBlogPost.nodes.map(({ title }) => ({
	id: slugify(title),
  title,
  }));

  await runScreenshots({
  	data: titles,
  	component: require.resolve('./src/printer-components/blog-post'),
  	outputDir: 'rainbow-og-images'
  });
}
```

---
_Source: https://npm.io/package/gatsby-plugin-printer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
