@ethercorps/sveltekit-og 2.0.0 → 2.0.1
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 +19 -18
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -7,8 +7,9 @@ Dynamically generate Open Graph images from an HTML+CSS template or Svelte compo
|
|
|
7
7
|
```bash
|
|
8
8
|
pnpm install -D @ethercorps/sveltekit-og
|
|
9
9
|
```
|
|
10
|
+
|
|
10
11
|
> Using with Cloudflare Pages or Workers then you have to provide `url` polyfill by just installing it as `devDependency`.
|
|
11
|
-
|
|
12
|
+
|
|
12
13
|
```bash
|
|
13
14
|
pnpm i -D url
|
|
14
15
|
```
|
|
@@ -45,21 +46,21 @@ const fontFile = await fetch('https://og-playground.vercel.app/inter-latin-ext-4
|
|
|
45
46
|
const fontData: ArrayBuffer = await fontFile.arrayBuffer();
|
|
46
47
|
|
|
47
48
|
export const GET: RequestHandler = async () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
return await ImageResponse(template, {
|
|
50
|
+
height: 630,
|
|
51
|
+
width: 1200,
|
|
52
|
+
fonts: [
|
|
53
|
+
{
|
|
54
|
+
name: 'Inter Latin',
|
|
55
|
+
data: fontData,
|
|
56
|
+
weight: 400
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
});
|
|
59
60
|
};
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
Then run `npm dev` and visit `localhost:5173/og` to view your generated PNG. Remember that hot module reloading does not work with server routes, so if you change your HTML or CSS, hard refresh the route to see changes.
|
|
63
|
+
Then run `npm dev` and visit `localhost:5173/og` to view your generated PNG. Remember that hot module reloading does not work with server routes, so if you change your HTML or CSS, hard refresh the route to see changes.
|
|
63
64
|
|
|
64
65
|
## Example Output
|
|
65
66
|
|
|
@@ -69,18 +70,17 @@ Then run `npm dev` and visit `localhost:5173/og` to view your generated PNG. Rem
|
|
|
69
70
|
|
|
70
71
|
When run in development, image headers contain `cache-control: no-cache, no-store`. In production, image headers contain `'cache-control': 'public, immutable, no-transform, max-age=31536000'`, which caches the image for 1 year. In both cases, the `'content-type': 'image/png'` is used.
|
|
71
72
|
|
|
72
|
-
|
|
73
73
|
## Styling
|
|
74
74
|
|
|
75
|
-
Notice that our example uses TailwindCSS classes (e.g. `tw="bg-gray-50"`). Alternatively, your HTML can contain style attributes using any of [the subset of CSS supported by Satori](https://github.com/vercel/satori#css).
|
|
75
|
+
Notice that our example uses TailwindCSS classes (e.g. `tw="bg-gray-50"`). Alternatively, your HTML can contain style attributes using any of [the subset of CSS supported by Satori](https://github.com/vercel/satori#css).
|
|
76
76
|
|
|
77
77
|
Satori supports only a subset of HTML and CSS. For full details, see [Satori’s documentation](https://github.com/vercel/satori#documentation). Notably, Satori only supports flex-based layouts.
|
|
78
78
|
|
|
79
79
|
## Fonts
|
|
80
80
|
|
|
81
|
-
Satori supports `ttf`, `otf`, and `woff` font formats. To maximize the font parsing speed, `ttf` or `otf` are recommended over `woff`.
|
|
81
|
+
Satori supports `ttf`, `otf`, and `woff` font formats; `woff2` is not supported. To maximize the font parsing speed, `ttf` or `otf` are recommended over `woff`.
|
|
82
82
|
|
|
83
|
-
By default, `@ethercorps/sveltekit-og` includes only 'Noto Sans' font. If you need to use other fonts, you can specify them as shown in the example. Notably, you can also import a font file that is stored locally within your project and are not required to use fetch.
|
|
83
|
+
By default, `@ethercorps/sveltekit-og` includes only 'Noto Sans' font. If you need to use other fonts, you can specify them as shown in the example. Notably, you can also import a font file that is stored locally within your project and are not required to use fetch.
|
|
84
84
|
|
|
85
85
|
## Examples
|
|
86
86
|
|
|
@@ -101,7 +101,7 @@ ImageResponse(
|
|
|
101
101
|
options : {
|
|
102
102
|
width ? : number = 1200
|
|
103
103
|
height ? : number = 630,
|
|
104
|
-
backgroundColor ? : string = "#fff"
|
|
104
|
+
backgroundColor ? : string = "#fff"
|
|
105
105
|
fonts ? : {
|
|
106
106
|
name: string,
|
|
107
107
|
data: ArrayBuffer,
|
|
@@ -142,6 +142,7 @@ componentToImageResponse(
|
|
|
142
142
|
## Changelog
|
|
143
143
|
|
|
144
144
|
### v1.2.3 Update (Breaking Changes)
|
|
145
|
+
|
|
145
146
|
> Now you have to install dependency by yourself which will make it easier to build for all plateforms.
|
|
146
147
|
|
|
147
148
|
```
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SatoriOptions } from 'satori';
|
|
2
2
|
import type { SvelteComponent } from 'svelte';
|
|
3
|
-
import toReactElement from './toReactElement';
|
|
3
|
+
import toReactElement from './toReactElement.js';
|
|
4
4
|
declare const ImageResponse: (htmlTemplate: string, optionsByUser: ImageResponseOptions) => Promise<Response>;
|
|
5
5
|
declare const componentToImageResponse: (component: typeof SvelteComponent, props: {} | undefined, optionsByUser: ImageResponseOptions) => Promise<Response>;
|
|
6
6
|
type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import satori, {} from 'satori';
|
|
2
|
-
import toReactElement from './toReactElement';
|
|
2
|
+
import toReactElement from './toReactElement.js';
|
|
3
3
|
import { svg2png, initialize } from 'svg2png-wasm';
|
|
4
4
|
let initialized = false;
|
|
5
5
|
const fontFile = await fetch('https://sveltekit-og.ethercorps.io/noto-sans.ttf');
|
|
@@ -31,7 +31,7 @@ const ImageResponse = async (htmlTemplate, optionsByUser) => {
|
|
|
31
31
|
}
|
|
32
32
|
const defaultConfig = {
|
|
33
33
|
width: options.width,
|
|
34
|
-
height: options.height
|
|
34
|
+
height: options.height // optional
|
|
35
35
|
};
|
|
36
36
|
if (Object.hasOwn(options, 'backgroundColor')) {
|
|
37
37
|
defaultConfig.backgroundColor = options.backgroundColor;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethercorps/sveltekit-og",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@playwright/test": "^1.
|
|
6
|
+
"@playwright/test": "^1.35.0",
|
|
7
7
|
"@sveltejs/adapter-auto": "next",
|
|
8
8
|
"@sveltejs/adapter-vercel": "^2.4.3",
|
|
9
9
|
"@sveltejs/kit": "1.10.0",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"postcss": "^8.4.24",
|
|
19
19
|
"prettier": "^2.8.8",
|
|
20
20
|
"prettier-plugin-svelte": "^2.10.1",
|
|
21
|
+
"prism-svelte": "^0.5.0",
|
|
21
22
|
"prismjs": "^1.29.0",
|
|
22
23
|
"svelte": "^3.59.1",
|
|
23
24
|
"svelte-check": "^2.10.3",
|