@growth-labs/opengraph 0.1.3
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/README.md +83 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +96 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +43 -0
- package/dist/options.js.map +1 -0
- package/dist/routes/og.d.ts +4 -0
- package/dist/routes/og.d.ts.map +1 -0
- package/dist/routes/og.js +73 -0
- package/dist/routes/og.js.map +1 -0
- package/dist/state.d.ts +5 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +15 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/generate.d.ts +8 -0
- package/dist/utils/generate.d.ts.map +1 -0
- package/dist/utils/generate.js +98 -0
- package/dist/utils/generate.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/r2.d.ts +10 -0
- package/dist/utils/r2.d.ts.map +1 -0
- package/dist/utils/r2.js +38 -0
- package/dist/utils/r2.js.map +1 -0
- package/dist/utils/template.d.ts +3 -0
- package/dist/utils/template.d.ts.map +1 -0
- package/dist/utils/template.js +162 -0
- package/dist/utils/template.js.map +1 -0
- package/dist/utils/url.d.ts +18 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +26 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/vite-plugin.d.ts +4 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +21 -0
- package/dist/vite-plugin.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @growth-labs/opengraph
|
|
2
|
+
|
|
3
|
+
Generates branded Open Graph images using Cloudflare Browser Rendering (Puppeteer). Screenshots HTML templates, caches in R2, serves via on-demand route. Two sizes per page: 1200×630 (Facebook/LinkedIn/Twitter) and 1200×675 (Google Discover 16:9).
|
|
4
|
+
|
|
5
|
+
**Requires:** Cloudflare Workers Paid plan (Browser Rendering access).
|
|
6
|
+
|
|
7
|
+
## Config
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import opengraph from '@growth-labs/opengraph'
|
|
11
|
+
|
|
12
|
+
opengraph({
|
|
13
|
+
publicDomain: 'media.fedweek.com', // R2 custom domain
|
|
14
|
+
r2Binding: 'MEDIA_BUCKET',
|
|
15
|
+
browserBinding: 'BROWSER',
|
|
16
|
+
brandName: 'FEDweek',
|
|
17
|
+
brandColors: {
|
|
18
|
+
primary: '#1a365d',
|
|
19
|
+
accent: '#e53e3e',
|
|
20
|
+
text: '#ffffff',
|
|
21
|
+
},
|
|
22
|
+
logoUrl: 'https://media.fedweek.com/logos/og-logo.png',
|
|
23
|
+
fontFamily: 'Inter',
|
|
24
|
+
fontWeight: '600',
|
|
25
|
+
route: { enabled: true, regenerateSecret: '...' },
|
|
26
|
+
format: 'png',
|
|
27
|
+
timeout: 10_000,
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## What It Injects
|
|
32
|
+
|
|
33
|
+
**Route:** `GET /og/[...path].png` — on-demand OG image generation. First request renders via Browser Rendering + caches to R2. Subsequent requests served from R2.
|
|
34
|
+
|
|
35
|
+
## Standalone Utilities
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { getOgImageUrl, getOgDiscoverUrl } from '@growth-labs/opengraph/utils'
|
|
39
|
+
import { generateOgImage } from '@growth-labs/opengraph/utils'
|
|
40
|
+
|
|
41
|
+
getOgImageUrl('media.fedweek.com', '/news/my-article')
|
|
42
|
+
// → https://media.fedweek.com/og/news/my-article.png
|
|
43
|
+
|
|
44
|
+
// Or generate programmatically (e.g. in publish workflow)
|
|
45
|
+
await generateOgImage(env.BROWSER, env.MEDIA_BUCKET, templateData, options)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Custom Templates
|
|
49
|
+
|
|
50
|
+
Override the built-in template with a function that returns HTML:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
opengraph({
|
|
54
|
+
template: (data) => `<html><body><h1>${data.title}</h1></body></html>`,
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Template receives: `{ title, subtitle, description, category, authorName, authorImageUrl, pageType }`
|
|
59
|
+
|
|
60
|
+
## Wrangler Bindings
|
|
61
|
+
|
|
62
|
+
```toml
|
|
63
|
+
[browser]
|
|
64
|
+
binding = "BROWSER"
|
|
65
|
+
|
|
66
|
+
[[r2_buckets]]
|
|
67
|
+
binding = "MEDIA_BUCKET"
|
|
68
|
+
bucket_name = "fedweek-public-media"
|
|
69
|
+
|
|
70
|
+
compatibility_flags = ["nodejs_compat"]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Integration Points
|
|
74
|
+
|
|
75
|
+
- **With @growth-labs/seo:** Consumer passes OG image URL into `generateMeta()`. No direct import between packages.
|
|
76
|
+
- **With @growth-labs/media:** Writes to `og/` prefix in the same R2 bucket. `ogKey()` in media utils generates matching keys.
|
|
77
|
+
|
|
78
|
+
## Key Patterns
|
|
79
|
+
|
|
80
|
+
- Virtual module: `virtual:growth-labs/opengraph/config`
|
|
81
|
+
- R2 key convention: `og/{page-path}.png` (aligns with `@growth-labs/media/utils` ogKey())
|
|
82
|
+
- `?regenerate=true` with shared secret to force re-render
|
|
83
|
+
- Browser Rendering has per-account concurrency limits — timeout protects against hangs
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import { type OpengraphOptions } from './options.js';
|
|
3
|
+
export default function opengraph(userOptions: OpengraphOptions): AstroIntegration;
|
|
4
|
+
export type { OpengraphOptions, ResolvedOpengraphOptions } from './options.js';
|
|
5
|
+
export { opengraphOptionsSchema } from './options.js';
|
|
6
|
+
export type { OgContext, OgGenerationResult, OgTemplateData } from './types.js';
|
|
7
|
+
export { generateOgImage } from './utils/generate.js';
|
|
8
|
+
export { invalidateCache } from './utils/r2.js';
|
|
9
|
+
export { defaultTemplate } from './utils/template.js';
|
|
10
|
+
export { getOgDiscoverUrl, getOgImageUrl, getOgUrls } from './utils/url.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,KAAK,gBAAgB,EAA0B,MAAM,cAAc,CAAA;AAI5E,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,WAAW,EAAE,gBAAgB,GAAG,gBAAgB,CA4BjF;AAED,YAAY,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrD,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { opengraphOptionsSchema } from './options.js';
|
|
2
|
+
import { _setContentProvider, _setTemplate } from './state.js';
|
|
3
|
+
import { growthLabsOpengraphPlugin } from './vite-plugin.js';
|
|
4
|
+
export default function opengraph(userOptions) {
|
|
5
|
+
const options = opengraphOptionsSchema.parse(userOptions);
|
|
6
|
+
if (userOptions.contentProvider) {
|
|
7
|
+
_setContentProvider(userOptions.contentProvider);
|
|
8
|
+
}
|
|
9
|
+
if (userOptions.template) {
|
|
10
|
+
_setTemplate(userOptions.template);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
name: '@growth-labs/opengraph',
|
|
14
|
+
hooks: {
|
|
15
|
+
'astro:config:setup': ({ injectRoute, updateConfig }) => {
|
|
16
|
+
updateConfig({
|
|
17
|
+
vite: { plugins: [growthLabsOpengraphPlugin(options)] },
|
|
18
|
+
});
|
|
19
|
+
if (options.route.enabled) {
|
|
20
|
+
injectRoute({
|
|
21
|
+
pattern: `/og/[...path].${options.format}`,
|
|
22
|
+
entrypoint: '@growth-labs/opengraph/routes/og',
|
|
23
|
+
prerender: false,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { opengraphOptionsSchema } from './options.js';
|
|
31
|
+
// Re-export utilities for direct consumption
|
|
32
|
+
export { generateOgImage } from './utils/generate.js';
|
|
33
|
+
export { invalidateCache } from './utils/r2.js';
|
|
34
|
+
export { defaultTemplate } from './utils/template.js';
|
|
35
|
+
export { getOgDiscoverUrl, getOgImageUrl, getOgUrls } from './utils/url.js';
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAE5D,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,WA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ZodString>;
|
|
5
|
+
r2Prefix: z.ZodDefault<z.ZodString>;
|
|
6
|
+
browserBinding: z.ZodDefault<z.ZodString>;
|
|
7
|
+
brandName: z.ZodOptional<z.ZodString>;
|
|
8
|
+
brandColors: z.ZodOptional<z.ZodObject<{
|
|
9
|
+
primary: z.ZodString;
|
|
10
|
+
accent: z.ZodOptional<z.ZodString>;
|
|
11
|
+
background: z.ZodOptional<z.ZodString>;
|
|
12
|
+
text: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
primary: string;
|
|
15
|
+
accent?: string | undefined;
|
|
16
|
+
background?: string | undefined;
|
|
17
|
+
text?: string | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
primary: string;
|
|
20
|
+
accent?: string | undefined;
|
|
21
|
+
background?: string | undefined;
|
|
22
|
+
text?: string | undefined;
|
|
23
|
+
}>>;
|
|
24
|
+
logoUrl: z.ZodOptional<z.ZodString>;
|
|
25
|
+
defaultSubtitle: z.ZodOptional<z.ZodString>;
|
|
26
|
+
fontFamily: z.ZodDefault<z.ZodString>;
|
|
27
|
+
fontWeight: z.ZodDefault<z.ZodString>;
|
|
28
|
+
template: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodString>>;
|
|
29
|
+
route: z.ZodDefault<z.ZodObject<{
|
|
30
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
31
|
+
regenerateSecret: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
regenerateSecret?: string | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
enabled?: boolean | undefined;
|
|
37
|
+
regenerateSecret?: string | undefined;
|
|
38
|
+
}>>;
|
|
39
|
+
contentProvider: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodAny], z.ZodUnknown>, z.ZodPromise<z.ZodNullable<z.ZodAny>>>>;
|
|
40
|
+
quality: z.ZodDefault<z.ZodNumber>;
|
|
41
|
+
format: z.ZodDefault<z.ZodEnum<["png", "jpeg"]>>;
|
|
42
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
publicDomain: string;
|
|
45
|
+
r2Binding: string;
|
|
46
|
+
r2Prefix: string;
|
|
47
|
+
browserBinding: string;
|
|
48
|
+
fontFamily: string;
|
|
49
|
+
fontWeight: string;
|
|
50
|
+
route: {
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
regenerateSecret?: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
quality: number;
|
|
55
|
+
format: "png" | "jpeg";
|
|
56
|
+
timeout: number;
|
|
57
|
+
brandName?: string | undefined;
|
|
58
|
+
brandColors?: {
|
|
59
|
+
primary: string;
|
|
60
|
+
accent?: string | undefined;
|
|
61
|
+
background?: string | undefined;
|
|
62
|
+
text?: string | undefined;
|
|
63
|
+
} | undefined;
|
|
64
|
+
logoUrl?: string | undefined;
|
|
65
|
+
defaultSubtitle?: string | undefined;
|
|
66
|
+
template?: ((args_0: any, ...args: unknown[]) => string) | undefined;
|
|
67
|
+
contentProvider?: ((args_0: string, args_1: any, ...args: unknown[]) => Promise<any>) | undefined;
|
|
68
|
+
}, {
|
|
69
|
+
publicDomain: string;
|
|
70
|
+
r2Binding?: string | undefined;
|
|
71
|
+
r2Prefix?: string | undefined;
|
|
72
|
+
browserBinding?: string | undefined;
|
|
73
|
+
brandName?: string | undefined;
|
|
74
|
+
brandColors?: {
|
|
75
|
+
primary: string;
|
|
76
|
+
accent?: string | undefined;
|
|
77
|
+
background?: string | undefined;
|
|
78
|
+
text?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
logoUrl?: string | undefined;
|
|
81
|
+
defaultSubtitle?: string | undefined;
|
|
82
|
+
fontFamily?: string | undefined;
|
|
83
|
+
fontWeight?: string | undefined;
|
|
84
|
+
template?: ((args_0: any, ...args: unknown[]) => string) | undefined;
|
|
85
|
+
route?: {
|
|
86
|
+
enabled?: boolean | undefined;
|
|
87
|
+
regenerateSecret?: string | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
contentProvider?: ((args_0: string, args_1: any, ...args: unknown[]) => Promise<any>) | undefined;
|
|
90
|
+
quality?: number | undefined;
|
|
91
|
+
format?: "png" | "jpeg" | undefined;
|
|
92
|
+
timeout?: number | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
export type OpengraphOptions = z.input<typeof opengraphOptionsSchema>;
|
|
95
|
+
export type ResolvedOpengraphOptions = z.output<typeof opengraphOptionsSchema>;
|
|
96
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AASvB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyCjC,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AACrE,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAA"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const brandColorsSchema = z.object({
|
|
3
|
+
primary: z.string(),
|
|
4
|
+
accent: z.string().optional(),
|
|
5
|
+
background: z.string().optional(),
|
|
6
|
+
text: z.string().optional(),
|
|
7
|
+
});
|
|
8
|
+
export const opengraphOptionsSchema = z.object({
|
|
9
|
+
// Required
|
|
10
|
+
publicDomain: z.string(),
|
|
11
|
+
// R2
|
|
12
|
+
r2Binding: z.string().default('MEDIA_BUCKET'),
|
|
13
|
+
r2Prefix: z.string().default('og/'),
|
|
14
|
+
// Browser Rendering
|
|
15
|
+
browserBinding: z.string().default('BROWSER'),
|
|
16
|
+
// Brand configuration
|
|
17
|
+
brandName: z.string().optional(),
|
|
18
|
+
brandColors: brandColorsSchema.optional(),
|
|
19
|
+
logoUrl: z.string().url().optional(),
|
|
20
|
+
defaultSubtitle: z.string().optional(),
|
|
21
|
+
fontFamily: z.string().default('Inter'),
|
|
22
|
+
fontWeight: z.string().default('600'),
|
|
23
|
+
// Custom template
|
|
24
|
+
template: z.function().args(z.any()).returns(z.string()).optional(),
|
|
25
|
+
// Route
|
|
26
|
+
route: z
|
|
27
|
+
.object({
|
|
28
|
+
enabled: z.boolean().default(true),
|
|
29
|
+
regenerateSecret: z.string().optional(),
|
|
30
|
+
})
|
|
31
|
+
.default({}),
|
|
32
|
+
// Content provider (for on-demand generation)
|
|
33
|
+
contentProvider: z
|
|
34
|
+
.function()
|
|
35
|
+
.args(z.string(), z.any())
|
|
36
|
+
.returns(z.promise(z.any().nullable()))
|
|
37
|
+
.optional(),
|
|
38
|
+
// Generation
|
|
39
|
+
quality: z.number().min(1).max(100).default(90),
|
|
40
|
+
format: z.enum(['png', 'jpeg']).default('png'),
|
|
41
|
+
timeout: z.number().default(10_000),
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,IAAI,EA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E,CAAC;IAEb,8CAA8C;IAC9C,eAAe,EAAE,CAAC;SAChB,QAAQ,EAAE;SACV,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC;SACzB,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;SACtC,QAAQ,EAAE;IAEZ,aAAa;IACb,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/C,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAC9C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;CACnC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"og.d.ts","sourceRoot":"","sources":["../../src/routes/og.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKrC,eAAO,MAAM,SAAS,QAAQ,CAAA;AAE9B,eAAO,MAAM,GAAG,EAAE,QAmFjB,CAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { getContentProvider, options } from 'virtual:growth-labs/opengraph/config';
|
|
2
|
+
import { generateOgImage } from '../utils/generate.js';
|
|
3
|
+
import { getCached, ogDiscoverKey, ogKey } from '../utils/r2.js';
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
export const GET = async (context) => {
|
|
6
|
+
const runtime = context.locals.runtime;
|
|
7
|
+
const env = runtime.env;
|
|
8
|
+
const r2 = env[options.r2Binding];
|
|
9
|
+
const browser = env[options.browserBinding];
|
|
10
|
+
const rawPath = context.params.path ?? '';
|
|
11
|
+
const format = options.format;
|
|
12
|
+
// Determine if this is a Discover variant request
|
|
13
|
+
const isDiscover = rawPath.endsWith('-discover');
|
|
14
|
+
const pagePath = isDiscover ? `/${rawPath.slice(0, -'-discover'.length)}` : `/${rawPath}`;
|
|
15
|
+
// Check for regeneration request
|
|
16
|
+
const url = new URL(context.request.url);
|
|
17
|
+
const wantsRegenerate = url.searchParams.get('regenerate') === 'true';
|
|
18
|
+
const secret = url.searchParams.get('secret');
|
|
19
|
+
if (wantsRegenerate) {
|
|
20
|
+
if (!options.route.regenerateSecret || secret !== options.route.regenerateSecret) {
|
|
21
|
+
return new Response('Unauthorized', { status: 401 });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Try serving from R2 cache
|
|
25
|
+
if (!wantsRegenerate) {
|
|
26
|
+
const key = isDiscover
|
|
27
|
+
? ogDiscoverKey(options.r2Prefix, pagePath, format)
|
|
28
|
+
: ogKey(options.r2Prefix, pagePath, format);
|
|
29
|
+
const cached = await getCached(r2, key);
|
|
30
|
+
if (cached) {
|
|
31
|
+
const contentType = format === 'jpeg' ? 'image/jpeg' : 'image/png';
|
|
32
|
+
return new Response(cached.body, {
|
|
33
|
+
headers: {
|
|
34
|
+
'Content-Type': contentType,
|
|
35
|
+
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
36
|
+
'X-OG-Cache': 'HIT',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Cache miss — need contentProvider
|
|
42
|
+
const contentProvider = getContentProvider();
|
|
43
|
+
if (!contentProvider) {
|
|
44
|
+
return new Response('OG image not found. Pre-generate via generateOgImage() or configure contentProvider.', { status: 404 });
|
|
45
|
+
}
|
|
46
|
+
const pageData = await contentProvider(pagePath, context);
|
|
47
|
+
if (!pageData) {
|
|
48
|
+
return new Response('Page not found', { status: 404 });
|
|
49
|
+
}
|
|
50
|
+
let result;
|
|
51
|
+
try {
|
|
52
|
+
result = await generateOgImage(pagePath, pageData, { r2, browser }, options, wantsRegenerate);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(`OG image generation failed for ${pagePath}:`, error);
|
|
56
|
+
return new Response('Generation failed', { status: 500 });
|
|
57
|
+
}
|
|
58
|
+
// Serve the requested variant
|
|
59
|
+
const key = isDiscover ? result.discover.key : result.og.key;
|
|
60
|
+
const object = await r2.get(key);
|
|
61
|
+
if (!object) {
|
|
62
|
+
return new Response('Generation failed', { status: 500 });
|
|
63
|
+
}
|
|
64
|
+
const contentType = format === 'jpeg' ? 'image/jpeg' : 'image/png';
|
|
65
|
+
return new Response(object.body, {
|
|
66
|
+
headers: {
|
|
67
|
+
'Content-Type': contentType,
|
|
68
|
+
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
69
|
+
'X-OG-Cache': 'MISS',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=og.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"og.js","sourceRoot":"","sources":["../../src/routes/og.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAGlF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEhE,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAA;AAE9B,MAAM,CAAC,MAAM,GAAG,GAAa,KAAK,EAAE,OAAO,EAAE,EAAE;IAC9C,MAAM,OAAO,GAAI,OAAO,CAAC,MAA8B,CAAC,OAAO,CAAA;IAC/D,MAAM,GAAG,GAAG,OAAO,CAAC,GAA8B,CAAA;IAElD,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAa,CAAA;IAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,CAAY,CAAA;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AE,CAAC,GAAG,CAAA;IAC5D,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,IAAI,QAAQ,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IAC1D,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAA;IAClE,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE;QAChC,OAAO,EAAE;YACR,cAAc,EAAE,WAAW;YAC3B,eAAe,EAAE,qCAAqC;YACtD,YAAY,EAAE,MAAM;SACpB;KACD,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function _setContentProvider(provider: (pagePath: string, context: any) => Promise<any>): void;
|
|
2
|
+
export declare function _setTemplate(template: (data: any) => string): void;
|
|
3
|
+
export declare function getContentProvider(): ((pagePath: string, context: any) => Promise<any>) | undefined;
|
|
4
|
+
export declare function getTemplate(): ((data: any) => string) | undefined;
|
|
5
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,GACxD,IAAI,CAEN;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAElE;AAED,wBAAgB,kBAAkB,IAC/B,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,GAClD,SAAS,CAEX;AAED,wBAAgB,WAAW,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAEjE"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let _contentProvider;
|
|
2
|
+
let _template;
|
|
3
|
+
export function _setContentProvider(provider) {
|
|
4
|
+
_contentProvider = provider;
|
|
5
|
+
}
|
|
6
|
+
export function _setTemplate(template) {
|
|
7
|
+
_template = template;
|
|
8
|
+
}
|
|
9
|
+
export function getContentProvider() {
|
|
10
|
+
return _contentProvider;
|
|
11
|
+
}
|
|
12
|
+
export function getTemplate() {
|
|
13
|
+
return _template;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,IAAI,gBAAgF,CAAA;AACpF,IAAI,SAA8C,CAAA;AAElD,MAAM,UAAU,mBAAmB,CAClC,QAA0D;IAE1D,gBAAgB,GAAG,QAAQ,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAA+B;IAC3D,SAAS,GAAG,QAAQ,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,kBAAkB;IAGjC,OAAO,gBAAgB,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,WAAW;IAC1B,OAAO,SAAS,CAAA;AACjB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data passed to the template function (built-in or custom).
|
|
3
|
+
*/
|
|
4
|
+
export interface OgTemplateData {
|
|
5
|
+
title: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
category?: string;
|
|
9
|
+
authorName?: string;
|
|
10
|
+
authorImageUrl?: string;
|
|
11
|
+
pageType?: 'article' | 'category' | 'author' | 'search' | 'landing' | 'newsletter' | 'product' | 'generic';
|
|
12
|
+
brandName?: string;
|
|
13
|
+
brandColors?: {
|
|
14
|
+
primary: string;
|
|
15
|
+
accent?: string;
|
|
16
|
+
background?: string;
|
|
17
|
+
text?: string;
|
|
18
|
+
};
|
|
19
|
+
logoUrl?: string;
|
|
20
|
+
fontFamily: string;
|
|
21
|
+
fontWeight: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result of a generation call.
|
|
25
|
+
*/
|
|
26
|
+
export interface OgGenerationResult {
|
|
27
|
+
og: {
|
|
28
|
+
key: string;
|
|
29
|
+
url: string;
|
|
30
|
+
};
|
|
31
|
+
discover: {
|
|
32
|
+
key: string;
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
cached: boolean;
|
|
36
|
+
generatedAt: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Context object providing access to Cloudflare bindings.
|
|
40
|
+
*/
|
|
41
|
+
export interface OgContext {
|
|
42
|
+
r2: R2Bucket;
|
|
43
|
+
browser: Fetcher;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EACN,SAAS,GACT,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,YAAY,GACZ,SAAS,GACT,SAAS,CAAA;IAEZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE;QACb,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,IAAI,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;IACD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,EAAE,EAAE;QACH,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACX,CAAA;IACD,QAAQ,EAAE;QACT,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACX,CAAA;IACD,MAAM,EAAE,OAAO,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,QAAQ,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;CAChB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ResolvedOpengraphOptions } from '../options.js';
|
|
2
|
+
import type { OgContext, OgGenerationResult, OgTemplateData } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generate OG images for a page. Checks R2 cache first; on miss,
|
|
5
|
+
* renders the template via Browser Rendering and writes both sizes to R2.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateOgImage(pagePath: string, data: OgTemplateData, context: OgContext, options: ResolvedOpengraphOptions, force?: boolean): Promise<OgGenerationResult>;
|
|
8
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/utils/generate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAQhF;;;GAGG;AACH,wBAAsB,eAAe,CACpC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,wBAAwB,EACjC,KAAK,UAAQ,GACX,OAAO,CAAC,kBAAkB,CAAC,CAgG7B"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import puppeteer from '@cloudflare/puppeteer';
|
|
2
|
+
import { getCached, ogDiscoverKey, ogKey, writeToR2 } from './r2.js';
|
|
3
|
+
import { defaultTemplate } from './template.js';
|
|
4
|
+
function toExactArrayBuffer(bytes) {
|
|
5
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Generate OG images for a page. Checks R2 cache first; on miss,
|
|
9
|
+
* renders the template via Browser Rendering and writes both sizes to R2.
|
|
10
|
+
*/
|
|
11
|
+
export async function generateOgImage(pagePath, data, context, options, force = false) {
|
|
12
|
+
const format = options.format;
|
|
13
|
+
const contentType = format === 'jpeg' ? 'image/jpeg' : 'image/png';
|
|
14
|
+
const keyOg = ogKey(options.r2Prefix, pagePath, format);
|
|
15
|
+
const keyDiscover = ogDiscoverKey(options.r2Prefix, pagePath, format);
|
|
16
|
+
const now = new Date().toISOString();
|
|
17
|
+
// Check R2 cache (both sizes must be present and title must match)
|
|
18
|
+
if (!force) {
|
|
19
|
+
const cachedOg = await getCached(context.r2, keyOg, data.title);
|
|
20
|
+
const cachedDiscover = await getCached(context.r2, keyDiscover, data.title);
|
|
21
|
+
if (cachedOg && cachedDiscover) {
|
|
22
|
+
return {
|
|
23
|
+
og: {
|
|
24
|
+
key: keyOg,
|
|
25
|
+
url: `https://${options.publicDomain}/${keyOg}`,
|
|
26
|
+
},
|
|
27
|
+
discover: {
|
|
28
|
+
key: keyDiscover,
|
|
29
|
+
url: `https://${options.publicDomain}/${keyDiscover}`,
|
|
30
|
+
},
|
|
31
|
+
cached: true,
|
|
32
|
+
generatedAt: cachedOg.customMetadata?.['x-og-generated-at'] ?? now,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Populate brand data from options into template data
|
|
37
|
+
const templateData = {
|
|
38
|
+
...data,
|
|
39
|
+
brandName: data.brandName ?? options.brandName,
|
|
40
|
+
brandColors: data.brandColors ?? options.brandColors,
|
|
41
|
+
logoUrl: data.logoUrl ?? options.logoUrl,
|
|
42
|
+
fontFamily: options.fontFamily,
|
|
43
|
+
fontWeight: options.fontWeight,
|
|
44
|
+
subtitle: data.subtitle ?? options.defaultSubtitle,
|
|
45
|
+
};
|
|
46
|
+
// Render HTML template
|
|
47
|
+
const templateFn = options.template ?? defaultTemplate;
|
|
48
|
+
const html = templateFn(templateData);
|
|
49
|
+
// Browser Rendering: one session, two screenshots
|
|
50
|
+
const browser = await puppeteer.launch(context.browser);
|
|
51
|
+
let ogBuffer;
|
|
52
|
+
let discoverBuffer;
|
|
53
|
+
try {
|
|
54
|
+
const page = await browser.newPage();
|
|
55
|
+
// Set viewport to the larger size (1200x675 Discover)
|
|
56
|
+
await page.setViewport({ width: 1200, height: 675, deviceScaleFactor: 1 });
|
|
57
|
+
await page.setContent(html, {
|
|
58
|
+
waitUntil: 'networkidle0',
|
|
59
|
+
timeout: options.timeout,
|
|
60
|
+
});
|
|
61
|
+
// Screenshot 1: Discover size (full viewport, 1200x675)
|
|
62
|
+
const discoverScreenshot = (await page.screenshot({
|
|
63
|
+
type: format === 'jpeg' ? 'jpeg' : undefined,
|
|
64
|
+
quality: format === 'jpeg' ? options.quality : undefined,
|
|
65
|
+
clip: { x: 0, y: 0, width: 1200, height: 675 },
|
|
66
|
+
}));
|
|
67
|
+
discoverBuffer = toExactArrayBuffer(discoverScreenshot);
|
|
68
|
+
// Screenshot 2: OG size (center-cropped to 1200x630)
|
|
69
|
+
const ogScreenshot = (await page.screenshot({
|
|
70
|
+
type: format === 'jpeg' ? 'jpeg' : undefined,
|
|
71
|
+
quality: format === 'jpeg' ? options.quality : undefined,
|
|
72
|
+
clip: { x: 0, y: 0, width: 1200, height: 630 },
|
|
73
|
+
}));
|
|
74
|
+
ogBuffer = toExactArrayBuffer(ogScreenshot);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await browser.close();
|
|
78
|
+
}
|
|
79
|
+
// Write both images to R2
|
|
80
|
+
const writeMetadata = { title: data.title, generatedAt: now, contentType };
|
|
81
|
+
await Promise.all([
|
|
82
|
+
writeToR2(context.r2, keyOg, ogBuffer, writeMetadata),
|
|
83
|
+
writeToR2(context.r2, keyDiscover, discoverBuffer, writeMetadata),
|
|
84
|
+
]);
|
|
85
|
+
return {
|
|
86
|
+
og: {
|
|
87
|
+
key: keyOg,
|
|
88
|
+
url: `https://${options.publicDomain}/${keyOg}`,
|
|
89
|
+
},
|
|
90
|
+
discover: {
|
|
91
|
+
key: keyDiscover,
|
|
92
|
+
url: `https://${options.publicDomain}/${keyDiscover}`,
|
|
93
|
+
},
|
|
94
|
+
cached: false,
|
|
95
|
+
generatedAt: now,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/utils/generate.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAG7C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,SAAS,kBAAkB,CAAC,KAAiB;IAC5C,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK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,EAAE,WAAW,OAAO,CAAC,YAAY,IAAI,KAAK,EAAE;SAC/C;QACD,QAAQ,EAAE;YACT,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,WAAW,OAAO,CAAC,YAAY,IAAI,WAAW,EAAE;SACrD;QACD,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,GAAG;KAChB,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { generateOgImage } from './generate.js';
|
|
2
|
+
export { getCached, invalidateCache, ogDiscoverKey, ogKey, writeToR2 } from './r2.js';
|
|
3
|
+
export { defaultTemplate } from './template.js';
|
|
4
|
+
export { getOgDiscoverUrl, getOgImageUrl, getOgUrls } from './url.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { generateOgImage } from './generate.js';
|
|
2
|
+
export { getCached, invalidateCache, ogDiscoverKey, ogKey, writeToR2 } from './r2.js';
|
|
3
|
+
export { defaultTemplate } from './template.js';
|
|
4
|
+
export { getOgDiscoverUrl, getOgImageUrl, getOgUrls } from './url.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function ogKey(prefix: string, pagePath: string, format: string): string;
|
|
2
|
+
export declare function ogDiscoverKey(prefix: string, pagePath: string, format: string): string;
|
|
3
|
+
export declare function getCached(bucket: R2Bucket, key: string, currentTitle?: string): Promise<R2ObjectBody | null>;
|
|
4
|
+
export declare function writeToR2(bucket: R2Bucket, key: string, body: ArrayBuffer, metadata: {
|
|
5
|
+
title: string;
|
|
6
|
+
generatedAt: string;
|
|
7
|
+
contentType: string;
|
|
8
|
+
}): Promise<R2Object>;
|
|
9
|
+
export declare function invalidateCache(bucket: R2Bucket, prefix: string, pagePath: string, format: string): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=r2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"r2.d.ts","sourceRoot":"","sources":["../../src/utils/r2.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG9E;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED,wBAAsB,SAAS,CAC9B,MAAM,EAAE,QAAQ,EAChB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAY9B;AAED,wBAAsB,SAAS,CAC9B,MAAM,EAAE,QAAQ,EAChB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE;IACT,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;CACnB,GACC,OAAO,CAAC,QAAQ,CAAC,CAWnB;AAED,wBAAsB,eAAe,CACpC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
package/dist/utils/r2.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { normalizePagePath } from './url.js';
|
|
2
|
+
export function ogKey(prefix, pagePath, format) {
|
|
3
|
+
const normalizedPath = normalizePagePath(pagePath);
|
|
4
|
+
return `${prefix}${normalizedPath}.${format}`;
|
|
5
|
+
}
|
|
6
|
+
export function ogDiscoverKey(prefix, pagePath, format) {
|
|
7
|
+
const normalizedPath = normalizePagePath(pagePath);
|
|
8
|
+
return `${prefix}${normalizedPath}-discover.${format}`;
|
|
9
|
+
}
|
|
10
|
+
export async function getCached(bucket, key, currentTitle) {
|
|
11
|
+
const object = await bucket.get(key);
|
|
12
|
+
if (!object)
|
|
13
|
+
return null;
|
|
14
|
+
if (currentTitle) {
|
|
15
|
+
const cachedTitle = object.customMetadata?.['x-og-title'];
|
|
16
|
+
if (cachedTitle && cachedTitle !== currentTitle) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return object;
|
|
21
|
+
}
|
|
22
|
+
export async function writeToR2(bucket, key, body, metadata) {
|
|
23
|
+
return bucket.put(key, body, {
|
|
24
|
+
httpMetadata: {
|
|
25
|
+
contentType: metadata.contentType,
|
|
26
|
+
cacheControl: 'public, max-age=31536000, immutable',
|
|
27
|
+
},
|
|
28
|
+
customMetadata: {
|
|
29
|
+
'x-og-title': metadata.title,
|
|
30
|
+
'x-og-generated-at': metadata.generatedAt,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export async function invalidateCache(bucket, prefix, pagePath, format) {
|
|
35
|
+
const keys = [ogKey(prefix, pagePath, format), ogDiscoverKey(prefix, pagePath, format)];
|
|
36
|
+
await Promise.all(keys.map((key) => bucket.delete(key)));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=r2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"r2.js","sourceRoot":"","sources":["../../src/utils/r2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE5C,MAAM,UAAU,KAAK,CAAC,MAAc,EAAE,QAAgB,EAAE,MAAc;IACrE,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,GAAG,MAAM,GAAG,cAAc,IAAI,MAAM,EAAE,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,QAAgB,EAAE,MAAc;IAC7E,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,GAAG,MAAM,GAAG,cAAc,aAAa,MAAM,EAAE,CAAA;AACvD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,MAAgB,EAChB,GAAW,EACX,YAAqB;IAErB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IAAI,YAAY,EAAE,CAAC;QAClB,MAAM,WAAW,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC,YAAY,CAAC,CAAA;QACzD,IAAI,WAAW,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;YACjD,OAAO,IAAI,CAAA;QACZ,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,MAAgB,EAChB,GAAW,EACX,IAAiB,EACjB,QAIC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE;QAC5B,YAAY,EAAE;YACb,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,YAAY,EAAE,qCAAqC;SACnD;QACD,cAAc,EAAE;YACf,YAAY,EAAE,QAAQ,CAAC,KAAK;YAC5B,mBAAmB,EAAE,QAAQ,CAAC,WAAW;SACzC;KACD,CAAC,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,MAAgB,EAChB,MAAc,EACd,QAAgB,EAChB,MAAc;IAEd,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;IACvF,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CA4J5D"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export function defaultTemplate(data) {
|
|
2
|
+
const bg = data.brandColors?.background ?? data.brandColors?.primary ?? '#1a1a2e';
|
|
3
|
+
const textColor = data.brandColors?.text ?? '#ffffff';
|
|
4
|
+
const accent = data.brandColors?.accent ?? '#e2725b';
|
|
5
|
+
const fontFamily = data.fontFamily;
|
|
6
|
+
const fontWeight = data.fontWeight;
|
|
7
|
+
const subtitle = data.subtitle ?? data.description;
|
|
8
|
+
const category = data.category ?? data.pageType;
|
|
9
|
+
const fontUrl = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(fontFamily)}:wght@400;${fontWeight};700&display=swap`;
|
|
10
|
+
return `<!DOCTYPE html>
|
|
11
|
+
<html>
|
|
12
|
+
<head>
|
|
13
|
+
<meta charset="utf-8">
|
|
14
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
15
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
16
|
+
<link href="${fontUrl}" rel="stylesheet">
|
|
17
|
+
<style>
|
|
18
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
19
|
+
|
|
20
|
+
body {
|
|
21
|
+
width: 1200px;
|
|
22
|
+
height: 675px;
|
|
23
|
+
background: ${bg};
|
|
24
|
+
color: ${textColor};
|
|
25
|
+
font-family: '${fontFamily}', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
padding: 56px 64px 48px;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
position: relative;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.top-bar {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: space-between;
|
|
37
|
+
margin-bottom: auto;
|
|
38
|
+
flex-shrink: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.brand {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
gap: 16px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.brand img {
|
|
48
|
+
height: 40px;
|
|
49
|
+
width: auto;
|
|
50
|
+
object-fit: contain;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.brand-name {
|
|
54
|
+
font-size: 20px;
|
|
55
|
+
font-weight: 400;
|
|
56
|
+
letter-spacing: 0.02em;
|
|
57
|
+
opacity: 0.85;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.category {
|
|
61
|
+
font-size: 16px;
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
text-transform: uppercase;
|
|
64
|
+
letter-spacing: 0.08em;
|
|
65
|
+
color: ${accent};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.title {
|
|
69
|
+
font-size: 56px;
|
|
70
|
+
font-weight: ${fontWeight};
|
|
71
|
+
line-height: 1.15;
|
|
72
|
+
letter-spacing: -0.02em;
|
|
73
|
+
margin-bottom: 16px;
|
|
74
|
+
display: -webkit-box;
|
|
75
|
+
-webkit-line-clamp: 3;
|
|
76
|
+
-webkit-box-orient: vertical;
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
flex-shrink: 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.subtitle {
|
|
82
|
+
font-size: 24px;
|
|
83
|
+
font-weight: 400;
|
|
84
|
+
line-height: 1.4;
|
|
85
|
+
opacity: 0.75;
|
|
86
|
+
display: -webkit-box;
|
|
87
|
+
-webkit-line-clamp: 2;
|
|
88
|
+
-webkit-box-orient: vertical;
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
flex-shrink: 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.bottom-bar {
|
|
94
|
+
margin-top: auto;
|
|
95
|
+
flex-shrink: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.accent-line {
|
|
99
|
+
width: 64px;
|
|
100
|
+
height: 4px;
|
|
101
|
+
background: ${accent};
|
|
102
|
+
margin-bottom: 20px;
|
|
103
|
+
border-radius: 2px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.author {
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
gap: 14px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.author img {
|
|
113
|
+
width: 44px;
|
|
114
|
+
height: 44px;
|
|
115
|
+
border-radius: 50%;
|
|
116
|
+
object-fit: cover;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.author-name {
|
|
120
|
+
font-size: 18px;
|
|
121
|
+
font-weight: 500;
|
|
122
|
+
opacity: 0.85;
|
|
123
|
+
}
|
|
124
|
+
</style>
|
|
125
|
+
</head>
|
|
126
|
+
<body>
|
|
127
|
+
<div class="top-bar">
|
|
128
|
+
<div class="brand">
|
|
129
|
+
${data.logoUrl ? `<img src="${data.logoUrl}" alt="">` : ''}
|
|
130
|
+
${data.brandName ? `<span class="brand-name">${escapeHtml(data.brandName)}</span>` : ''}
|
|
131
|
+
</div>
|
|
132
|
+
${category ? `<span class="category">${escapeHtml(category)}</span>` : ''}
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div style="flex: 1; display: flex; flex-direction: column; justify-content: center;">
|
|
136
|
+
<h1 class="title">${escapeHtml(data.title)}</h1>
|
|
137
|
+
${subtitle ? `<p class="subtitle">${escapeHtml(subtitle)}</p>` : ''}
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div class="bottom-bar">
|
|
141
|
+
<div class="accent-line"></div>
|
|
142
|
+
${data.authorName
|
|
143
|
+
? `
|
|
144
|
+
<div class="author">
|
|
145
|
+
${data.authorImageUrl ? `<img src="${data.authorImageUrl}" alt="">` : ''}
|
|
146
|
+
<span class="author-name">${escapeHtml(data.authorName)}</span>
|
|
147
|
+
</div>
|
|
148
|
+
`
|
|
149
|
+
: ''}
|
|
150
|
+
</div>
|
|
151
|
+
</body>
|
|
152
|
+
</html>`;
|
|
153
|
+
}
|
|
154
|
+
function escapeHtml(str) {
|
|
155
|
+
return str
|
|
156
|
+
.replace(/&/g, '&')
|
|
157
|
+
.replace(/</g, '<')
|
|
158
|
+
.replace(/>/g, '>')
|
|
159
|
+
.replace(/"/g, '"')
|
|
160
|
+
.replace(/'/g, ''');
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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AIrD,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;MACxC,QAAQ,CAAC,CAAC,CAAC,uBAAuB,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;;;;;MAMpE,IAAI,CAAC,UAAU;QACd,CAAC,CAAC;;QAEE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,IAAI,CAAC,cAAc,WAAW,CAAC,CAAC,CAAC,EAAE;kCAC5C,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;;KAExD;QACD,CAAC,CAAC,EACJ;;;QAGM,CAAA;AACR,CAAC;AAED,SAAS,UAAU,CAAC,GAAW;IAC9B,OAAO,GAAG;SACR,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function getOgImageUrl(publicDomain: string, pagePath: string, options?: {
|
|
2
|
+
prefix?: string;
|
|
3
|
+
format?: 'png' | 'jpeg';
|
|
4
|
+
}): string;
|
|
5
|
+
export declare function getOgDiscoverUrl(publicDomain: string, pagePath: string, options?: {
|
|
6
|
+
prefix?: string;
|
|
7
|
+
format?: 'png' | 'jpeg';
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function getOgUrls(publicDomain: string, pagePath: string, options?: {
|
|
10
|
+
prefix?: string;
|
|
11
|
+
format?: 'png' | 'jpeg';
|
|
12
|
+
}): {
|
|
13
|
+
og: string;
|
|
14
|
+
discover: string;
|
|
15
|
+
};
|
|
16
|
+
/** Exported for use by r2.ts key builders */
|
|
17
|
+
export declare function normalizePagePath(pagePath: string): string;
|
|
18
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAC5B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CAAE,GACpD,MAAM,CAKR;AAED,wBAAgB,gBAAgB,CAC/B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CAAE,GACpD,MAAM,CAKR;AAED,wBAAgB,SAAS,CACxB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CAAE,GACpD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAKlC;AAED,6CAA6C;AAC7C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI1D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function getOgImageUrl(publicDomain, pagePath, options) {
|
|
2
|
+
const prefix = options?.prefix ?? 'og/';
|
|
3
|
+
const ext = options?.format ?? 'png';
|
|
4
|
+
const normalizedPath = normalizePagePath(pagePath);
|
|
5
|
+
return `https://${publicDomain}/${prefix}${normalizedPath}.${ext}`;
|
|
6
|
+
}
|
|
7
|
+
export function getOgDiscoverUrl(publicDomain, pagePath, options) {
|
|
8
|
+
const prefix = options?.prefix ?? 'og/';
|
|
9
|
+
const ext = options?.format ?? 'png';
|
|
10
|
+
const normalizedPath = normalizePagePath(pagePath);
|
|
11
|
+
return `https://${publicDomain}/${prefix}${normalizedPath}-discover.${ext}`;
|
|
12
|
+
}
|
|
13
|
+
export function getOgUrls(publicDomain, pagePath, options) {
|
|
14
|
+
return {
|
|
15
|
+
og: getOgImageUrl(publicDomain, pagePath, options),
|
|
16
|
+
discover: getOgDiscoverUrl(publicDomain, pagePath, options),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Exported for use by r2.ts key builders */
|
|
20
|
+
export function normalizePagePath(pagePath) {
|
|
21
|
+
let path = pagePath.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
22
|
+
if (path === '')
|
|
23
|
+
path = 'index';
|
|
24
|
+
return path;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAC5B,YAAoB,EACpB,QAAgB,EAChB,OAAsD;IAEtD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,KAAK,CAAA;IACvC,MAAM,GAAG,GAAG,OAAO,EAAE,MAAM,IAAI,KAAK,CAAA;IACpC,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,WAAW,YAAY,IAAI,MAAM,GAAG,cAAc,IAAI,GAAG,EAAE,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC/B,YAAoB,EACpB,QAAgB,EAChB,OAAsD;IAEtD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,KAAK,CAAA;IACvC,MAAM,GAAG,GAAG,OAAO,EAAE,MAAM,IAAI,KAAK,CAAA;IACpC,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,WAAW,YAAY,IAAI,MAAM,GAAG,cAAc,aAAa,GAAG,EAAE,CAAA;AAC5E,CAAC;AAED,MAAM,UAAU,SAAS,CACxB,YAAoB,EACpB,QAAgB,EAChB,OAAsD;IAEtD,OAAO;QACN,EAAE,EAAE,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC;QAClD,QAAQ,EAAE,gBAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC;KAC3D,CAAA;AACF,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IACjD,IAAI,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC3D,IAAI,IAAI,KAAK,EAAE;QAAE,IAAI,GAAG,OAAO,CAAA;IAC/B,OAAO,IAAI,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAK5D,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,CAiBlF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const VIRTUAL_MODULE_ID = 'virtual:growth-labs/opengraph/config';
|
|
2
|
+
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
3
|
+
export function growthLabsOpengraphPlugin(config) {
|
|
4
|
+
const { contentProvider: _cp, template: _t, ...staticConfig } = config;
|
|
5
|
+
return {
|
|
6
|
+
name: 'growth-labs-opengraph-config',
|
|
7
|
+
resolveId(id) {
|
|
8
|
+
if (id === VIRTUAL_MODULE_ID)
|
|
9
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
10
|
+
},
|
|
11
|
+
load(id) {
|
|
12
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
13
|
+
return [
|
|
14
|
+
`export const options = ${JSON.stringify(staticConfig)};`,
|
|
15
|
+
`export { getContentProvider, getTemplate } from '@growth-labs/opengraph/state';`,
|
|
16
|
+
].join('\n');
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=vite-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAGA,MAAM,iBAAiB,GAAG,sCAAsC,CAAA;AAChE,MAAM,0BAA0B,GAAG,KAAK,iBAAiB,EAAE,CAAA;AAE3D,MAAM,UAAU,yBAAyB,CAAC,MAAgC;IACzE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,MAAiC,CAAA;IAEjG,OAAO;QACN,IAAI,EAAE,8BAA8B;QACpC,SAAS,CAAC,EAAE;YACX,IAAI,EAAE,KAAK,iBAAiB;gBAAE,OAAO,0BAA0B,CAAA;QAChE,CAAC;QACD,IAAI,CAAC,EAAE;YACN,IAAI,EAAE,KAAK,0BAA0B,EAAE,CAAC;gBACvC,OAAO;oBACN,0BAA0B,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;oBACzD,iFAAiF;iBACjF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACb,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@growth-labs/opengraph",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc",
|
|
7
|
+
"check": "biome check src/",
|
|
8
|
+
"test": "vitest run",
|
|
9
|
+
"test:watch": "vitest"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./utils": {
|
|
17
|
+
"types": "./dist/utils/index.d.ts",
|
|
18
|
+
"import": "./dist/utils/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./routes/og": {
|
|
21
|
+
"types": "./dist/routes/og.d.ts",
|
|
22
|
+
"import": "./dist/routes/og.js",
|
|
23
|
+
"default": "./dist/routes/og.js"
|
|
24
|
+
},
|
|
25
|
+
"./state": {
|
|
26
|
+
"types": "./dist/state.d.ts",
|
|
27
|
+
"import": "./dist/state.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@cloudflare/puppeteer": "^1.0.4",
|
|
40
|
+
"zod": "^3.23.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"astro": "^6.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@cloudflare/workers-types": "^4.20241230.0",
|
|
47
|
+
"astro": "^6.0.0",
|
|
48
|
+
"typescript": "^5.7.0",
|
|
49
|
+
"vite": "^7.0.0",
|
|
50
|
+
"vitest": "^3.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|