# Code snippet Open Graph Image Template

A dark code snippet card with a full width code window and language chip.

- Page: https://www.shadcn-ui-blocks.com/open-graph-images/code-snippet
- Category: [Developer](https://www.shadcn-ui-blocks.com/open-graph-images/developer), Open source
- Theme: dark, with light and dark renditions
- Preview PNG: https://www.shadcn-ui-blocks.com/open-graph-images/code-snippet/preview

## Install

```bash
npx shadcn@latest add @shadcn-ui-blocks/og-image-code-snippet
```

The code is part of Pro and Team: the install needs an API key from either plan (https://www.shadcn-ui-blocks.com/docs/shadcn-cli).

Use the Code snippet template for posts whose subject is the code itself, a hook, a helper, a config. It runs a full width editor window across the card with the snippet's title as the header, drawn code inside, and a filename, language chip, and brand around it, so the card reads as code at a glance.

## How it works

This template is a metadata image route for the Next.js App Router. The file exports `size`, `contentType`, and `alt` values plus a default async function that returns an `ImageResponse`. When the snippet page is shared, satori converts the JSX into an SVG document, the runtime rasterizes that SVG into a 1200 by 630 PNG, and Next.js serves the result and wires the `og:image` and `twitter:image` tags into the page head automatically. The code is drawn from bars rather than real text, so it stays legible at thumbnail size where actual source would turn to noise.

## Install

Install with the shadcn CLI using your Shadcn UI Blocks API key:

```bash
npx shadcn@latest add @shadcn-ui-blocks/og-image-code-snippet
```

The file lands at `app/opengraph-image.tsx`, which makes it the site wide share card. Move it into the snippet segment, for example `app/snippets/[slug]/opengraph-image.tsx`, when each snippet has its own page. You can also copy the code from this page straight into your project.

The card renders text with Inter, read from `assets/fonts` at your project root with `node:fs` so the font files never ship to the browser. Download the latin woff files for weights 400, 500, 600, and 700 from [Fontsource](https://fontsource.org/fonts/inter) and save them as `assets/fonts/inter-latin-400-normal.woff` and so on.

## Customize

The `content` object holds `brand`, the `filename` shown in the window header, the `title`, the `language` chip, and the `url`. The `codeLines` array above the template draws the editor body as indent, width, and color tuples; reshape it to echo your snippet's shape, keeping the light accents sparse. To generate a card per snippet, accept `params` in the default export and pull the title, filename, and language from your content. Keep the title to one line at its 40px size.

satori supports a focused subset of CSS: flexbox layout only, flat colors, and an explicit `display: flex` on any element with multiple children. Keep those rules in mind if you rework the layout.
