og-route-kit 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ New: `og-route-kit audit`, a whole-site check for the sharing tags and images people never look at until a link previews wrong.
6
+
7
+ ```bash
8
+ npx og-route-kit audit --sitemap https://example.com/sitemap.xml
9
+ npx og-route-kit audit --url https://example.com/blog/post --json report.json
10
+ ```
11
+
12
+ It crawls a sitemap (indexes followed two levels deep, `.gz` unzipped), a list of URLs, or a single page, then reports what is broken on each page and what is broken across pages. No new runtime dependencies, no browser: it fetches HTML and image headers only.
13
+
14
+ ### Checks
15
+
16
+ - **Page**: `page-unreachable`, `title-missing`, `description-missing`.
17
+ - **Image tag**: `image-missing` (no `og:image`), `image-format` (PNG and JPEG pass; WebP, GIF and AVIF warn; anything else is an error).
18
+ - **Image file**: `image-unreachable`, `image-size` — reads PNG, JPEG (SOF past EXIF/ICC) and WebP (VP8, VP8L, VP8X) headers and flags images narrower than 1200 px or outside 2% of the 1.9047 ratio a 1200x630 card needs, `image-too-large` (over 5 MB, X's limit).
19
+ - **Text and URL tags**: absolute `og:url`, `og:title` and `og:description` presence, and relative or empty values.
20
+ - **Twitter / X**: `twitter-card-missing`, and `twitter-image-missing` only when no usable `og:image` exists, so a page with a good card is not flagged twice.
21
+ - **Across pages**: `image-duplicate` — several pages sharing one card means the card says nothing about any of them.
22
+
23
+ ### Options
24
+
25
+ `--sitemap`, `--urls` (file or `-` for stdin), `--url` (repeatable), `--limit` (even sampling across the whole list, deterministic run to run), `--only` (a subset of checks, skipping image fetches nobody asked for), `--concurrency` (default 4, capped at 8), `--timeout`, `--max-bytes`, `--json [path]` (report on stdout, table on stderr), `--fail-on error|warn|never`, `--quiet`.
26
+
27
+ Exit codes: `0` nothing at or above `--fail-on`, `1` findings, `2` usage error or the page list could not be read.
28
+
29
+ ### Docs
30
+
31
+ - [`docs/audit.md`](https://github.com/pixelbrew-studio/og-route-kit/blob/main/docs/audit.md): every check with an example finding, the sampling rule, the JSON report shape, and a GitHub Action that runs the audit on a schedule.
32
+ - The README's "Audit any site" section opens with the two commands above.
33
+
34
+ ## 0.1.0
35
+
36
+ First public release. A narrow toolkit for typed Open Graph image routes in Next.js App Router projects.
37
+
38
+ ### Route factory (`og-route-kit/next`)
39
+
40
+ - `createOgRoute` returns an App Router `GET` handler that normalizes query params, renders your TSX card with `next/og`, and returns an `ImageResponse`.
41
+ - Missing required params return `400` with `Cache-Control: no-store`.
42
+ - Image responses default to `DEFAULT_CACHE_CONTROL` (`public, max-age=0, s-maxage=86400, stale-while-revalidate=604800`) and `X-Content-Type-Options: nosniff`; pass `headers` to override.
43
+
44
+ ### Param normalization (`og-route-kit/core`)
45
+
46
+ - `normalizeOgParams` applies defaults and fallbacks, required fields, whitespace collapsing, trimming, and deterministic `max` truncation.
47
+ - Fields without a `max` are capped at `DEFAULT_OG_PARAM_MAX` (512) so untrusted query input cannot reach the renderer unbounded.
48
+ - `normalizeText` and `OgParamError` are exported for custom handling.
49
+
50
+ ### Metadata helper (`og-route-kit/next`)
51
+
52
+ - `createSocialMetadata` builds Open Graph and Twitter metadata for website and article pages, with matching image lists for both.
53
+ - Optional `includeDefaultImageFallback` lists a committed static image after the generated route image.
54
+
55
+ ### Core helpers (`og-route-kit/core`)
56
+
57
+ - `buildOgImageUrl` builds an encoded route URL while preserving existing query params and hash fragments.
58
+ - `OG_IMAGE_SIZES` and `resolveOgImageSize` provide size presets (`og` 1200x630, `twitter` 1200x675, `square` 1200x1200) and custom sizes.
59
+
60
+ ### CLI
61
+
62
+ - `og-route-kit check` verifies a running route returns a valid PNG.
63
+ - `og-route-kit export` writes the rendered PNG to disk, for example as a static fallback in `public/`.
64
+ - `og-route-kit preview` prints preview URLs for a route.
65
+ - `check` and `export` reject non-2xx responses, non-PNG content types, corrupt PNG bodies, responses over `--max-bytes` (default `8000000`), and requests over `--timeout` (default `30000` ms).
66
+
67
+ ### Example cards (`og-route-kit/examples/cards`)
68
+
69
+ - Product, article, and changelog cards that render through `createOgRoute`, plus a Next App Router example app that serves them.
70
+
71
+ ### Requirements
72
+
73
+ - Node.js 20 or newer.
74
+ - Peer dependencies: `next` >= 14.0.0 and `react` >= 18.2.0.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pixelbrew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,283 @@
1
- # Temporary Holding Version
1
+ # og-route-kit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/pixelbrew-studio/og-route-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/pixelbrew-studio/og-route-kit/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/pixelbrew-studio/og-route-kit/blob/main/LICENSE)
5
+
6
+ Typed `next/og` image routes from your own TSX cards, with query-param defaults, metadata helpers, and a CLI to check and export. For Next.js App Router projects. Not a hosted renderer, visual editor, or template marketplace.
7
+
8
+ ![A 1200x630 Open Graph card reading "Ship better social cards.", rendered by og-route-kit's own route](https://raw.githubusercontent.com/pixelbrew-studio/og-route-kit/main/demo/cards/product-card.png)
9
+
10
+ ```bash
11
+ npm i og-route-kit
12
+ ```
13
+
14
+ `next` (>= 14) and `react` (>= 18.2) are peer dependencies: `npm i next react`. Node.js 20 or newer.
15
+
16
+ ```tsx
17
+ // app/api/og/route.tsx
18
+ import { createOgRoute } from "og-route-kit/next";
19
+ import { ProductOgCard } from "@/og/ProductOgCard";
20
+
21
+ export const GET = createOgRoute({
22
+ defaults: { title: "Ship better social cards.", description: "Code-rendered Open Graph images." },
23
+ fields: { title: { max: 140, required: true } },
24
+ render: ProductOgCard,
25
+ });
26
+ ```
27
+
28
+ ```ts
29
+ // app/pricing/page.tsx (`social` comes from createSocialMetadata, see Usage)
30
+ export const metadata = social.website({
31
+ title: "Pricing", description: "Simple usage-based pricing.", path: "/pricing",
32
+ image: { title: "Usage-based pricing." },
33
+ });
34
+ ```
35
+
36
+ [Demo](https://pixelbrew-studio.github.io/og-route-kit/) · [Usage](#usage) · [API](#api) · [CLI](#cli) · [Changelog](https://github.com/pixelbrew-studio/og-route-kit/blob/main/CHANGELOG.md)
37
+
38
+ ## What you get over calling `next/og` directly
39
+
40
+ | You get | How |
41
+ | --- | --- |
42
+ | Typed query params | Per-field `defaults`, `required`, and `max`. Your card receives a typed props object. A missing required param returns `400` with `Cache-Control: no-store`. |
43
+ | Deterministic text cleanup | Whitespace is collapsed and trimmed, and long values are truncated at `max`. Fields without a `max` are still capped at 512 characters. |
44
+ | Cache headers | `public, max-age=0, s-maxage=86400, stale-while-revalidate=604800` plus `X-Content-Type-Options: nosniff` by default. Override with `headers`. |
45
+ | Metadata helper | `createSocialMetadata` emits Open Graph and Twitter metadata from the same inputs, with the same image list for both and an optional static PNG fallback. |
46
+ | CLI | `check`, `export`, and `preview` against a running route, and `audit` for a whole site's `og:image`. |
47
+ | Example cards | Product, article, and changelog cards, plus a runnable Next example app. |
48
+ | What it does not do | No hosted renderer, no visual editor, and no CSS beyond what Satori (the renderer behind `next/og`) supports. |
49
+
50
+ ## Usage
51
+
52
+ ### Install
53
+
54
+ ```bash
55
+ npm i og-route-kit next react
56
+ ```
57
+
58
+ `og-route-kit` expects Node.js 20 or newer. It supports Next.js 14 and newer, so its engine is intentionally not tightened to the Next.js 16 floor. The included Next.js 16 example requires Node.js 20.9.0 or newer.
59
+
60
+ To install straight from GitHub, pin a commit or tag for reproducible builds. GitHub installs run the package `prepare` script and build `dist` from source during installation:
61
+
62
+ ```bash
63
+ npm i github:pixelbrew-studio/og-route-kit#v0.1.0-dogfood.20260630
64
+ ```
65
+
66
+ ### Route
67
+
68
+ Create an App Router route:
69
+
70
+ ```tsx
71
+ // app/api/og/route.tsx
72
+ import { createOgRoute } from "og-route-kit/next";
73
+
74
+ import { ProductOgCard } from "@/og/ProductOgCard";
75
+
76
+ export const runtime = "edge";
77
+
78
+ export const GET = createOgRoute({
79
+ size: "og",
80
+ defaults: {
81
+ eyebrow: "Acme",
82
+ title: "Ship better social cards.",
83
+ description: "Code-rendered Open Graph images for product pages.",
84
+ },
85
+ fields: {
86
+ eyebrow: { max: 80 },
87
+ title: { max: 140, required: true },
88
+ description: { max: 180 },
89
+ },
90
+ render: ProductOgCard,
91
+ });
92
+ ```
93
+
94
+ The card is a plain component that returns Satori-compatible JSX. The example app has [three complete cards](https://github.com/pixelbrew-studio/og-route-kit/tree/main/examples/next-app/og).
95
+
96
+ ### Metadata
97
+
98
+ Build metadata once and reuse it:
99
+
100
+ ```ts
101
+ // lib/social.ts
102
+ import { createSocialMetadata } from "og-route-kit/next";
103
+
104
+ export const social = createSocialMetadata({
105
+ siteUrl: "https://acme.com",
106
+ siteName: "Acme",
107
+ twitter: "@acme",
108
+ imageRoute: "/api/og",
109
+ defaultImage: "/og-image.png",
110
+ includeDefaultImageFallback: true,
111
+ });
112
+ ```
113
+
114
+ ```ts
115
+ // app/pricing/page.tsx
116
+ import type { Metadata } from "next";
117
+
118
+ import { social } from "@/lib/social";
119
+
120
+ export const metadata: Metadata = social.website({
121
+ title: "Pricing",
122
+ description: "Simple usage-based pricing.",
123
+ path: "/pricing",
124
+ image: {
125
+ eyebrow: "Pricing",
126
+ title: "Usage-based pricing.",
127
+ description: "Start small. Scale when needed.",
128
+ },
129
+ });
130
+ ```
131
+
132
+ `defaultImage` is used when a page does not pass `image` params. It is not, by itself, a backup for a dynamic route that fails after a page has emitted `/api/og?...`. Set `includeDefaultImageFallback: true` to emit both images when page-specific image params are present: the generated route image first, then `defaultImage` second. Twitter metadata stays a string URL list in the same order.
133
+
134
+ ### Static fallback
135
+
136
+ Keep a committed PNG in `public/` and list it as the static fallback. Export it from your own route:
137
+
138
+ ```bash
139
+ npx og-route-kit export \
140
+ --url "http://localhost:3000/api/og?title=Pixelbrew&description=Landing+page" \
141
+ --out public/og/default.png
142
+ ```
143
+
144
+ Then point `defaultImage` at it, for example `defaultImage: "/og/default.png"`.
145
+
146
+ ## Audit any site
147
+
148
+ Is sharing broken on your site, and where? `audit` reads every page in a sitemap, fetches the `og:image` each one points at, and checks the bytes: reachable, a real PNG or JPEG (not an HTML error page served as an image), 1200x630 or a larger image of the same shape, under 300 KB. It exits `1` on errors, so CI can use it.
149
+
150
+ ```bash
151
+ npx og-route-kit audit --sitemap https://example.com/sitemap.xml --limit 20
152
+ ```
153
+
154
+ ```txt
155
+ https://example.com/pricing
156
+ error image-format image is served as text/html and the body looks like HTML, not an image
157
+
158
+ 12 pages · 1 error · 5 warnings
159
+ ```
160
+
161
+ Every check, the platform limits behind them, JSON output, and a GitHub Actions recipe: [docs/audit.md](https://github.com/pixelbrew-studio/og-route-kit/blob/main/docs/audit.md).
162
+
163
+ ## CLI
164
+
165
+ Check a running route:
166
+
167
+ ```bash
168
+ npx og-route-kit check \
169
+ --url "http://localhost:3000/api/og?title=Hello"
170
+ ```
171
+
172
+ Export a static fallback PNG from a running route:
173
+
174
+ ```bash
175
+ npx og-route-kit export \
176
+ --url "http://localhost:3000/api/og?title=Hello" \
177
+ --out public/og-image.png
178
+ ```
179
+
180
+ Print preview URLs:
181
+
182
+ ```bash
183
+ npx og-route-kit preview --origin http://localhost:3000 --route /api/og
184
+ ```
185
+
186
+ `check` and `export` reject non-2xx responses, non-PNG content types, corrupt PNG bodies, responses over `--max-bytes` (default `8000000`), and requests that exceed `--timeout` (default `30000` milliseconds).
187
+
188
+ ## API
189
+
190
+ ### `createOgRoute`
191
+
192
+ Creates a Next App Router `GET` handler that normalizes search params and returns an `ImageResponse`.
193
+
194
+ ```ts
195
+ import { createOgRoute } from "og-route-kit/next";
196
+ ```
197
+
198
+ Missing required query fields return `400` with `Cache-Control: no-store`. Successful image responses default to `Cache-Control: public, max-age=0, s-maxage=86400, stale-while-revalidate=604800` (exported as `DEFAULT_CACHE_CONTROL`); pass `headers` to override that cache policy for your route.
199
+
200
+ ### `createSocialMetadata`
201
+
202
+ Builds Open Graph and Twitter metadata for website and article pages.
203
+
204
+ ```ts
205
+ import { createSocialMetadata } from "og-route-kit/next";
206
+ ```
207
+
208
+ Metadata inputs (`title`, `description`, `path`, `image`) are treated as trusted page configuration. A `path` or image value that is a full `http(s)` URL is used verbatim, so do not pass raw end-user input into these fields, or `canonical` and `og:url` could point off-origin.
209
+
210
+ `defaultImage` is a default for pages that omit `image`; it does not automatically back up failed dynamic image routes. To list a committed PNG after the dynamic route image, set `includeDefaultImageFallback: true` and keep `defaultImage` pointed at the static asset.
211
+
212
+ ### `normalizeOgParams`
213
+
214
+ Framework-independent field normalization:
215
+
216
+ - missing, empty, and whitespace-only values use a field fallback or default
217
+ - whitespace collapses by default
218
+ - strings trim before validation
219
+ - `max` truncates deterministically; fields without a `max` are still capped at `DEFAULT_OG_PARAM_MAX` (512) so untrusted query input cannot reach the renderer unbounded
220
+ - required fields fail clearly when no usable value exists
221
+
222
+ ```ts
223
+ import { normalizeOgParams } from "og-route-kit/core";
224
+ ```
225
+
226
+ ### `buildOgImageUrl`
227
+
228
+ Builds an encoded route URL while preserving existing query params and hash fragments.
229
+
230
+ ```ts
231
+ import { buildOgImageUrl } from "og-route-kit/core";
232
+ ```
233
+
234
+ ### Example cards
235
+
236
+ `ProductCard`, `ArticleCard`, and `ChangelogCard` are exported from `og-route-kit/examples/cards` for trying the route factory without writing a card first.
237
+
238
+ ## Example App
239
+
240
+ Build the package and run the example route from a clone of this repository:
241
+
242
+ ```bash
243
+ pnpm install
244
+ pnpm build
245
+ pnpm --filter og-route-kit-next-app-example exec next dev -p 3000
246
+ ```
247
+
248
+ Open `http://localhost:3000/api/og?title=Hello&description=World`. The route should return a `1200 x 630` PNG.
249
+
250
+ The cards shown in this README and on the [demo page](https://pixelbrew-studio.github.io/og-route-kit/) in [`demo/cards`](https://github.com/pixelbrew-studio/og-route-kit/tree/main/demo/cards) are real output of the example routes, exported with `og-route-kit export`.
251
+
252
+ ## Development
253
+
254
+ ```bash
255
+ pnpm install
256
+ pnpm run ci
257
+ ```
258
+
259
+ Useful targeted commands:
260
+
261
+ ```bash
262
+ pnpm typecheck
263
+ pnpm test
264
+ pnpm build
265
+ pnpm example:build
266
+ pnpm pack:check
267
+ ```
268
+
269
+ For a full local route check, run:
270
+
271
+ ```bash
272
+ pnpm verify:local
273
+ ```
274
+
275
+ That starts the example app, checks the OG route, exports a test PNG to `.context/og-image-test.png`, and stops the server.
276
+
277
+ ## Contributing
278
+
279
+ Read [CONTRIBUTING.md](https://github.com/pixelbrew-studio/og-route-kit/blob/main/CONTRIBUTING.md). Keep changes focused on the Next-first route kit workflow.
280
+
281
+ ## Release
282
+
283
+ Releases are published from a version tag by [`release.yml`](https://github.com/pixelbrew-studio/og-route-kit/blob/main/.github/workflows/release.yml). The checklist lives in [docs/release.md](https://github.com/pixelbrew-studio/og-route-kit/blob/main/docs/release.md).
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node