nuxt-og-image 1.1.1 → 1.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/README.md +4 -5
- package/dist/module.json +1 -1
- package/dist/module.mjs +7 -2
- package/dist/runtime/nitro/providers/satori/index.mjs +2 -4
- package/dist/runtime/nitro/resvg/node.d.ts +3 -0
- package/dist/runtime/nitro/resvg/node.mjs +6 -0
- package/dist/runtime/nitro/resvg/wasm.d.ts +2 -0
- package/dist/runtime/nitro/resvg/wasm.mjs +31 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ Enlightened OG Image generation for Nuxt 3.
|
|
|
39
39
|
- 🤖 Browser provider: Supporting painless, complex templates
|
|
40
40
|
- ✨ Prerendering enabled for static images
|
|
41
41
|
- 📸 Feeling lazy? Just generate screenshots with options for hiding elements, waiting for animations, and more
|
|
42
|
+
- ⚙️ Edge / WASM compatible
|
|
42
43
|
|
|
43
44
|
## Install
|
|
44
45
|
|
|
@@ -94,16 +95,14 @@ For this guide, you will create your Satori OG image using the default component
|
|
|
94
95
|
|
|
95
96
|
Within your `pages/index.vue`, use `defineOgImageStatic` or `OgImageStatic` to define your `og:image` component.
|
|
96
97
|
|
|
97
|
-
Make sure you have defined some metadata
|
|
98
|
+
Make sure you have defined some metadata as props will be inferred from it.
|
|
98
99
|
|
|
99
100
|
```vue
|
|
100
101
|
<script lang="ts" setup>
|
|
101
102
|
// 1. make sure you have some meta
|
|
102
|
-
|
|
103
|
+
useSeoMeta({
|
|
103
104
|
title: 'Home',
|
|
104
|
-
|
|
105
|
-
{ name: 'description', content: 'My awesome home page.' },
|
|
106
|
-
],
|
|
105
|
+
description: 'My awesome home page.',
|
|
107
106
|
})
|
|
108
107
|
// 2a. Use the Composition API
|
|
109
108
|
defineOgImageStatic()
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { resolve, relative } from 'pathe';
|
|
|
10
10
|
import { tinyws } from 'tinyws';
|
|
11
11
|
import sirv from 'sirv';
|
|
12
12
|
import { copy } from 'fs-extra';
|
|
13
|
+
import { provider } from 'std-env';
|
|
13
14
|
import { createBirpcGroup } from 'birpc';
|
|
14
15
|
import { stringify, parse } from 'flatted';
|
|
15
16
|
|
|
@@ -219,7 +220,7 @@ const module = defineNuxtModule({
|
|
|
219
220
|
return resolve(`../dist/${p}`);
|
|
220
221
|
};
|
|
221
222
|
nuxt.options.experimental.componentIslands = true;
|
|
222
|
-
const isEdge = (process.env.NITRO_PRESET || "").includes("edge");
|
|
223
|
+
const isEdge = provider === "stackblitz" || (process.env.NITRO_PRESET || "").includes("edge");
|
|
223
224
|
addTemplate({
|
|
224
225
|
filename: "nuxt-og-image.d.ts",
|
|
225
226
|
getContents: () => {
|
|
@@ -295,7 +296,11 @@ export {}
|
|
|
295
296
|
});
|
|
296
297
|
nitroConfig.publicAssets = nitroConfig.publicAssets || [];
|
|
297
298
|
nitroConfig.publicAssets.push({ dir: fontDir, maxAge: 31536e3 });
|
|
298
|
-
|
|
299
|
+
if (isEdge && config.experimentalNitroBrowser)
|
|
300
|
+
nitroConfig.virtual["#nuxt-og-image/browser"] = `export { createBrowser } from '${runtimeDir}/nitro/browsers/${isEdge ? "lambda" : "default"}'`;
|
|
301
|
+
else
|
|
302
|
+
nitroConfig.virtual["#nuxt-og-image/browser"] = `export { createBrowser } from '${runtimeDir}/nitro/browsers/default'`;
|
|
303
|
+
nitroConfig.virtual["#nuxt-og-image/resvg"] = `import resvg from '${runtimeDir}/nitro/resvg/${isEdge ? "wasm" : "node"}'; export { resvg }`;
|
|
299
304
|
nitroConfig.virtual["#nuxt-og-image/provider"] = `
|
|
300
305
|
import satori from '${runtimeDir}/nitro/providers/satori'
|
|
301
306
|
import browser from '${runtimeDir}/nitro/providers/browser'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { html as convertHtmlToSatori } from "satori-html";
|
|
2
2
|
import satori from "satori";
|
|
3
3
|
import { parseURL } from "ufo";
|
|
4
|
-
import { Resvg } from "@resvg/resvg-js";
|
|
5
4
|
import twemoji from "twemoji";
|
|
6
5
|
import { loadFont, walkSatoriTree } from "./utils.mjs";
|
|
7
6
|
import imageSrc from "./plugins/imageSrc.mjs";
|
|
@@ -9,13 +8,12 @@ import twClasses from "./plugins/twClasses.mjs";
|
|
|
9
8
|
import flex from "./plugins/flex.mjs";
|
|
10
9
|
import emojis from "./plugins/emojis.mjs";
|
|
11
10
|
import { fonts, satoriOptions } from "#nuxt-og-image/config";
|
|
11
|
+
import { resvg } from "#nuxt-og-image/resvg";
|
|
12
12
|
export default {
|
|
13
13
|
name: "satori",
|
|
14
14
|
createPng: async function createPng(baseUrl, options) {
|
|
15
15
|
const svg = await this.createSvg(baseUrl, options);
|
|
16
|
-
|
|
17
|
-
const pngData = resvg.render();
|
|
18
|
-
return pngData.asPng();
|
|
16
|
+
return resvg(svg, options);
|
|
19
17
|
},
|
|
20
18
|
createVNode: async function createVNode(baseUrl, options) {
|
|
21
19
|
const url = parseURL(baseUrl);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Resvg, initWasm } from "@resvg/resvg-wasm";
|
|
2
|
+
import { resolvePath } from "mlly";
|
|
3
|
+
import { dirname, join } from "pathe";
|
|
4
|
+
import { $fetch } from "ofetch";
|
|
5
|
+
let wasm = null;
|
|
6
|
+
async function useResvgWasm() {
|
|
7
|
+
if (wasm)
|
|
8
|
+
return wasm;
|
|
9
|
+
try {
|
|
10
|
+
const path = join(
|
|
11
|
+
dirname(await resolvePath("@resvg/resvg-wasm")),
|
|
12
|
+
"index_bg.wasm"
|
|
13
|
+
);
|
|
14
|
+
const fs = await import("node:fs/promises");
|
|
15
|
+
wasm = await fs.readFile(path);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
wasm = await $fetch("https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm", {
|
|
18
|
+
responseType: "arrayBuffer"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return wasm;
|
|
22
|
+
}
|
|
23
|
+
export default async function(svg, options) {
|
|
24
|
+
const resvgWasm = await useResvgWasm();
|
|
25
|
+
if (!resvgWasm)
|
|
26
|
+
return false;
|
|
27
|
+
await initWasm(resvgWasm);
|
|
28
|
+
const resvg = new Resvg(svg, options);
|
|
29
|
+
const pngData = resvg.render();
|
|
30
|
+
return pngData.asPng();
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"packageManager": "pnpm@7.8.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@nuxt/kit": "3.1.0",
|
|
30
30
|
"@resvg/resvg-js": "^2.2.0",
|
|
31
|
+
"@resvg/resvg-wasm": "^2.2.0",
|
|
31
32
|
"@types/fs-extra": "^11.0.1",
|
|
32
33
|
"birpc": "^0.2.3",
|
|
33
34
|
"chalk": "^5.2.0",
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
"satori": "^0.1.1",
|
|
46
47
|
"satori-html": "^0.3.2",
|
|
47
48
|
"sirv": "^2.0.2",
|
|
49
|
+
"std-env": "^3.3.1",
|
|
48
50
|
"tinyws": "^0.1.0",
|
|
49
51
|
"twemoji": "^14.0.2",
|
|
50
52
|
"ufo": "^1.0.1"
|