@ethercorps/sveltekit-og 0.0.6 → 0.1.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 +14 -16
- package/index.d.ts +1 -2
- package/index.js +6 -6
- package/package.json +16 -3
- package/vendors/resvg.wasm +0 -0
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Install `@ethercorps/sveltekit-og`, then use it inside a server endpoint route (
|
|
|
9
9
|
|
|
10
10
|
```typescript
|
|
11
11
|
// /routes/og/+server.ts
|
|
12
|
-
import { ImageResponse } from '
|
|
12
|
+
import { ImageResponse } from '@ethercorps/sveltekit-og';
|
|
13
13
|
import type { RequestHandler } from './$types';
|
|
14
14
|
|
|
15
15
|
const template = `
|
|
@@ -30,10 +30,8 @@ const template = `
|
|
|
30
30
|
</div>
|
|
31
31
|
</div>
|
|
32
32
|
`;
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const fontData400: ArrayBuffer = await fontFile400.arrayBuffer();
|
|
36
|
-
const fontData700: ArrayBuffer = await fontFile700.arrayBuffer();
|
|
33
|
+
const fontFile = await fetch('https://og-playground.vercel.app/inter-latin-ext-400-normal.woff');
|
|
34
|
+
const fontData: ArrayBuffer = await fontFile.arrayBuffer();
|
|
37
35
|
|
|
38
36
|
export const GET: RequestHandler = async () => {
|
|
39
37
|
return new ImageResponse(template, {
|
|
@@ -42,13 +40,8 @@ export const GET: RequestHandler = async () => {
|
|
|
42
40
|
fonts: [
|
|
43
41
|
{
|
|
44
42
|
name: 'Inter Latin',
|
|
45
|
-
data:
|
|
43
|
+
data: fontData,
|
|
46
44
|
weight: 400
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: 'Inter Latin',
|
|
50
|
-
data: fontData700,
|
|
51
|
-
weight: 700
|
|
52
45
|
}
|
|
53
46
|
]
|
|
54
47
|
});
|
|
@@ -60,7 +53,12 @@ Then run `pnpm dev` and access localhost:5173/og, the React element will be rend
|
|
|
60
53
|
|
|
61
54
|

|
|
62
55
|
|
|
63
|
-
Read more about the API, supported features and check out the examples
|
|
56
|
+
Read more about the API, supported features and check out the examples on Satori Playground.
|
|
57
|
+
|
|
58
|
+
## Examples:
|
|
59
|
+
- `ImageResponse` · [_source_](/src/routes/+server.ts) · [_demo_](https://sveltekit-og-five.vercel.app)
|
|
60
|
+
- `componentToImageResponse` · [_source_](/src/routes/component-og/) · [_demo_](https://sveltekit-og-five.vercel.app/component-og)
|
|
61
|
+
|
|
64
62
|
|
|
65
63
|
## API Reference
|
|
66
64
|
|
|
@@ -105,13 +103,13 @@ During development, the `cache-control: no-cache, no-store` header is used inste
|
|
|
105
103
|
|
|
106
104
|
Please refer to [Satori’s documentation](https://github.com/vercel/satori#documentation) for a list of supported HTML and CSS features.
|
|
107
105
|
|
|
108
|
-
By default, `@ethercorps/sveltekit-og` only has the '
|
|
106
|
+
By default, `@ethercorps/sveltekit-og` only has the 'Noto Sans' font included. If you need to use other fonts, you can pass them in the `fonts` option.
|
|
109
107
|
|
|
110
108
|
|
|
111
109
|
## Acknowledgements
|
|
112
110
|
|
|
113
111
|
This project will not be possible without the following projects:
|
|
114
112
|
|
|
115
|
-
- [Satori](https://github.com/vercel/satori)
|
|
116
|
-
- [Google Fonts](https://fonts.google.com
|
|
117
|
-
- [Resvg
|
|
113
|
+
- [Satori & @vercel/og](https://github.com/vercel/satori)
|
|
114
|
+
- [Noto by Google Fonts](https://fonts.google.com/noto)
|
|
115
|
+
- [Resvg.js](https://github.com/yisibl/resvg-js)
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { SvelteComponent } from 'svelte';
|
|
2
1
|
import type { SatoriOptions } from 'satori';
|
|
3
2
|
export declare const ImageResponse: {
|
|
4
3
|
new (htmlTemplate: string, optionsByUser: ImageResponseOptions): {};
|
|
5
4
|
};
|
|
6
5
|
export declare const componentToImageResponse: {
|
|
7
|
-
new (component:
|
|
6
|
+
new (component: any, props: {} | undefined, optionsByUser: ImageResponseOptions): {};
|
|
8
7
|
};
|
|
9
8
|
export declare type ImageResponseOptions = ConstructorParameters<typeof Response>[1] & ImageOptions;
|
|
10
9
|
declare type ImageOptions = {
|
package/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { html as toReactNode } from 'satori-html';
|
|
2
2
|
import satori from 'satori';
|
|
3
3
|
import { Resvg, initWasm } from '@resvg/resvg-wasm';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
import { readFileSync } from 'fs';
|
|
6
4
|
import { fileURLToPath } from 'url';
|
|
7
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const resSvgWasm = initWasm(
|
|
9
|
-
const fontFile = await fetch('https://og-
|
|
6
|
+
const resSvgWasm = initWasm(fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm'));
|
|
7
|
+
const fontFile = await fetch('https://sveltekit-og-five.vercel.app/noto-sans.ttf');
|
|
10
8
|
const fontData = await fontFile.arrayBuffer();
|
|
11
9
|
export const ImageResponse = class {
|
|
12
10
|
constructor(htmlTemplate, optionsByUser) {
|
|
@@ -17,11 +15,13 @@ export const ImageResponse = class {
|
|
|
17
15
|
const svg = await satori(toReactNode(htmlTemplate), {
|
|
18
16
|
width: options.width,
|
|
19
17
|
height: options.height,
|
|
18
|
+
debug: options.debug,
|
|
20
19
|
fonts: options.fonts || [
|
|
21
20
|
{
|
|
22
|
-
name: '
|
|
21
|
+
name: 'sans serif',
|
|
23
22
|
data: fontData,
|
|
24
|
-
style: 'normal'
|
|
23
|
+
style: 'normal',
|
|
24
|
+
weight: 700
|
|
25
25
|
}
|
|
26
26
|
]
|
|
27
27
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethercorps/sveltekit-og",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@playwright/test": "^1.27.1",
|
|
@@ -27,9 +27,22 @@
|
|
|
27
27
|
"satori": "^0.0.42",
|
|
28
28
|
"satori-html": "^0.2.0"
|
|
29
29
|
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"open graph image",
|
|
32
|
+
"open graph",
|
|
33
|
+
"og image",
|
|
34
|
+
"og:image",
|
|
35
|
+
"social",
|
|
36
|
+
"card",
|
|
37
|
+
"sveltekit og",
|
|
38
|
+
"sveltekit-og",
|
|
39
|
+
"@ethercorps/sveltekit-og"
|
|
40
|
+
],
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": "https://github.com/etherCorps/sveltekit-og",
|
|
43
|
+
"homepage": "https://github.com/etherCorps/sveltekit-og#readme",
|
|
30
44
|
"exports": {
|
|
31
45
|
"./package.json": "./package.json",
|
|
32
|
-
".": "./index.js"
|
|
33
|
-
"./vendors/resvg.wasm": "./vendors/resvg.wasm"
|
|
46
|
+
".": "./index.js"
|
|
34
47
|
}
|
|
35
48
|
}
|
package/vendors/resvg.wasm
DELETED
|
Binary file
|