Socket
Socket
Sign inDemoInstall

og-images-generator

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

og-images-generator

Generate OG images from a static folder. Extract metadata from HTML pages. No headless browser involved.


Version published
Maintainers
1
Created
Source

og-images-generator

NPM Downloads ISC License GitHub PRs Welcome
TypeScript Prettier EditorConfig

Generate OG images from a static folder. Extract metadata from HTML pages. No headless browser involved.

Installation

npm i og-images-generator

Create a og-images.config.js in your current workspace root.

See demos/vanilla/og-images.config.js for a full working example.

The gist is:

// ./og-images.config.js

import {
	html,
	styled,
	OG_DIMENSIONS,
	SOURCE_SANS_FONT,
} from 'og-images-generator';

/** @type {import('og-images-generator').RenderOptions} */
export const renderOptions = {
	satori: { fonts: [await SOURCE_SANS_FONT()], ...OG_DIMENSIONS },
};

/** @type {import('og-images-generator').Template} */
export const template = ({ metadata }) => {
	if ('og:title' in metadata === false) throw Error('Missing title!');
	if ('og:description' in metadata === false)
		throw Error('Missing description!');

	const title = metadata['og:title'];
	const description = metadata['og:description'];

	return html` <!--  -->
		<div style=${styles.container}>
			<div style=${styles.foo}>
				${icon.main}
				<!-- ... -->
			</div>
		</div>`;
};

const tokens = {
	primaryColor: `rgb(82,245,187)`,
};

const icons = {
	main: html`
		<svg>
			<!-- ... -->
		</svg>
	`,
};

const styles = {
	container: styled.div`
		display: flex;
		height: 100%;
		width: 100%;
		/* ... */
	`,

	foo: styled.div`
		display: flex;
		color: ${tokens.primaryColor};
		/* ... */
	`,
};

You need to export renderOptions and template from your og-images-generator configuration file.

[!NOTE]
styled.div is a dummy strings concatenation literal (to get syntax highlighting).
div is the only needed (and available) tag, as it makes no difference anyway.

Also, you don't need to wrap interpolated HTML attributes with quotes (e.g. style="${foo}").
<foo-bar style=${styles.baz}></foo-bar> just works.


[!TIP]
Recommended VS Code extensions:

  • Styled Components for inline CSS highlighting: styled-components.vscode-styled-components
  • HTML highlighting: bierner.lit-html

Usage

CLI

npx generate-og

# defaults to
npx generate-og --base dist --out dist/og --json dist/og/index.json

Programmatic (JS API)

import { generateOgImages } from 'og-images-generator/api';

await generateOgImages(/* options */);

References


Other projects 👀


Find this project useful?

GitHub


🔗  JulianCataldo.com

Keywords

FAQs

Package last updated on 07 Feb 2024

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