nuxt-og-image 3.0.0-beta.4 → 3.0.0-beta.40
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 -4
- package/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{IconCSS.6583687a.js → IconCSS.783314f6.js} +1 -1
- package/dist/client/_nuxt/IconCSS.7e8f1f7b.css +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/88cd699e-6f5a-4788-a59e-8158fb29f04b.json +1 -0
- package/dist/client/_nuxt/entry.47aab0b4.css +1 -0
- package/dist/client/_nuxt/entry.e11cb5fa.js +137 -0
- package/dist/client/_nuxt/{error-404.214d08e9.js → error-404.c187917f.js} +1 -1
- package/dist/client/_nuxt/{error-500.f9a9234a.js → error-500.a1ce074a.js} +1 -1
- package/dist/client/index.html +5 -5
- package/dist/module.d.mts +45 -26
- package/dist/module.d.ts +45 -26
- package/dist/module.json +2 -2
- package/dist/module.mjs +176 -100
- package/dist/runtime/cache.d.ts +7 -10
- package/dist/runtime/cache.mjs +40 -27
- package/dist/runtime/components/OgImage/OgImage.d.ts +5 -0
- package/dist/runtime/components/OgImage/{index.mjs → OgImage.mjs} +1 -1
- package/dist/runtime/components/OgImage/OgImageScreenshot.d.ts +5 -0
- package/dist/runtime/components/OgImage/{Screenshot.mjs → OgImageScreenshot.mjs} +1 -1
- package/dist/runtime/components/Templates/{Official → Community}/BrandedLogo.vue +3 -2
- package/dist/runtime/components/Templates/Community/Nuxt.vue +6 -5
- package/dist/runtime/components/Templates/Community/NuxtSeo.vue +137 -0
- package/dist/runtime/components/Templates/{Official → Community}/SimpleBlog.vue +7 -5
- package/dist/runtime/components/Templates/Community/UnJs.vue +108 -0
- package/dist/runtime/components/Templates/{Official → Community}/Wave.vue +3 -2
- package/dist/runtime/components/Templates/{Official → Community}/WithEmoji.vue +3 -2
- package/dist/runtime/composables/defineOgImage.d.ts +2 -23
- package/dist/runtime/composables/defineOgImage.mjs +33 -116
- package/dist/runtime/composables/defineOgImageComponent.d.ts +3 -0
- package/dist/runtime/composables/defineOgImageComponent.mjs +8 -0
- package/dist/runtime/composables/defineOgImageScreenshot.d.ts +2 -0
- package/dist/runtime/composables/defineOgImageScreenshot.mjs +14 -0
- package/dist/runtime/core/bindings/css-inline/node.d.ts +2 -5
- package/dist/runtime/core/bindings/css-inline/node.mjs +2 -10
- package/dist/runtime/core/bindings/resvg/stackblitz.d.ts +40 -0
- package/dist/runtime/core/bindings/resvg/stackblitz.mjs +6 -0
- package/dist/runtime/core/bindings/resvg/wasm.mjs +2 -3
- package/dist/runtime/core/bindings/satori/stackblitz.mjs +13 -0
- package/dist/runtime/core/bindings/satori/wasm.d.ts +6 -0
- package/dist/runtime/core/bindings/satori/wasm.mjs +14 -0
- package/dist/runtime/core/cache/emojis.d.ts +1 -0
- package/dist/runtime/core/cache/emojis.mjs +5 -0
- package/dist/runtime/core/cache/htmlPayload.d.ts +5 -0
- package/dist/runtime/core/cache/htmlPayload.mjs +6 -0
- package/dist/runtime/core/cache/prerender.d.ts +1 -1
- package/dist/runtime/core/cache/prerender.mjs +1 -1
- package/dist/runtime/core/env/assets.d.ts +0 -1
- package/dist/runtime/core/env/assets.mjs +0 -4
- package/dist/runtime/core/font/fetch.d.ts +2 -3
- package/dist/runtime/core/font/fetch.mjs +32 -15
- package/dist/runtime/core/html/applyEmojis.d.ts +3 -0
- package/dist/runtime/core/html/applyEmojis.mjs +37 -0
- package/dist/runtime/core/html/applyInlineCss.d.ts +3 -0
- package/dist/runtime/core/html/applyInlineCss.mjs +32 -0
- package/dist/runtime/core/html/devIframeTemplate.d.ts +2 -0
- package/dist/runtime/core/html/{fetch.mjs → devIframeTemplate.mjs} +33 -42
- package/dist/runtime/core/html/fetchIsland.d.ts +3 -0
- package/dist/runtime/core/html/fetchIsland.mjs +17 -0
- package/dist/runtime/core/options/fetch.d.ts +1 -1
- package/dist/runtime/core/options/fetch.mjs +10 -5
- package/dist/runtime/core/options/normalise.d.ts +2 -2
- package/dist/runtime/core/options/normalise.mjs +3 -2
- package/dist/runtime/core/renderers/chromium/index.mjs +6 -7
- package/dist/runtime/core/renderers/chromium/screenshot.d.ts +2 -3
- package/dist/runtime/core/renderers/chromium/screenshot.mjs +8 -8
- package/dist/runtime/core/renderers/satori/fonts.d.ts +2 -2
- package/dist/runtime/core/renderers/satori/fonts.mjs +2 -2
- package/dist/runtime/core/renderers/satori/index.d.ts +2 -3
- package/dist/runtime/core/renderers/satori/index.mjs +25 -22
- package/dist/runtime/core/renderers/satori/instances.d.ts +3 -0
- package/dist/runtime/core/renderers/satori/instances.mjs +15 -0
- package/dist/runtime/core/renderers/satori/plugins/emojis.mjs +15 -13
- package/dist/runtime/core/renderers/satori/plugins/imageSrc.mjs +23 -10
- package/dist/runtime/core/renderers/satori/plugins/unocss.d.ts +2 -0
- package/dist/runtime/core/renderers/satori/plugins/unocss.mjs +45 -0
- package/dist/runtime/core/renderers/satori/utils.d.ts +2 -3
- package/dist/runtime/core/renderers/satori/vnodes.d.ts +2 -3
- package/dist/runtime/core/renderers/satori/vnodes.mjs +16 -6
- package/dist/runtime/core/utils/resolveRendererContext.d.ts +2 -6
- package/dist/runtime/core/utils/resolveRendererContext.mjs +42 -27
- package/dist/runtime/core/utils/wasm.d.ts +3 -0
- package/dist/runtime/core/utils/wasm.mjs +16 -0
- package/dist/runtime/nitro/plugins/nuxt-content.mjs +3 -4
- package/dist/runtime/nitro/plugins/prerender.d.ts +1 -1
- package/dist/runtime/nitro/plugins/prerender.mjs +20 -12
- package/dist/runtime/nitro/utils.d.ts +2 -0
- package/dist/runtime/nitro/utils.mjs +17 -0
- package/dist/runtime/nuxt/plugins/og-image-canonical-urls.server.mjs +31 -0
- package/dist/runtime/nuxt/plugins/route-rule-og-image.server.mjs +16 -50
- package/dist/runtime/nuxt/utils.d.ts +2 -0
- package/dist/runtime/nuxt/utils.mjs +53 -0
- package/dist/runtime/server/routes/__og-image__/debug.json.d.ts +1 -3
- package/dist/runtime/server/routes/__og-image__/debug.json.mjs +4 -8
- package/dist/runtime/server/routes/__og-image__/image.mjs +87 -0
- package/dist/runtime/types.d.ts +75 -25
- package/dist/runtime/utils.d.ts +4 -0
- package/dist/runtime/utils.mjs +11 -0
- package/dist/runtime/utils.pure.d.ts +5 -0
- package/dist/runtime/utils.pure.mjs +43 -0
- package/package.json +28 -30
- package/virtual.d.ts +49 -0
- package/dist/client/_nuxt/IconCSS.8f429b14.css +0 -1
- package/dist/client/_nuxt/builds/meta/0ca67bfd-95de-4c16-8f0a-055751cdca51.json +0 -1
- package/dist/client/_nuxt/entry.089f6f0f.js +0 -137
- package/dist/client/_nuxt/entry.434c2c45.css +0 -1
- package/dist/client/grid.png +0 -0
- package/dist/runtime/components/OgImage/Cached.d.ts +0 -5
- package/dist/runtime/components/OgImage/Cached.mjs +0 -10
- package/dist/runtime/components/OgImage/Dynamic.d.ts +0 -8
- package/dist/runtime/components/OgImage/Dynamic.mjs +0 -10
- package/dist/runtime/components/OgImage/Screenshot.d.ts +0 -6
- package/dist/runtime/components/OgImage/Static.d.ts +0 -8
- package/dist/runtime/components/OgImage/Static.mjs +0 -10
- package/dist/runtime/components/OgImage/WithoutCache.d.ts +0 -5
- package/dist/runtime/components/OgImage/WithoutCache.mjs +0 -10
- package/dist/runtime/components/OgImage/index.d.ts +0 -5
- package/dist/runtime/components/Templates/Official/Fallback.vue +0 -147
- package/dist/runtime/core/bindings/css-inline/mock.d.ts +0 -5
- package/dist/runtime/core/bindings/css-inline/mock.mjs +0 -3
- package/dist/runtime/core/bindings/satori/yoga-wasm.mjs +0 -7
- package/dist/runtime/core/bindings/sharp/wasm.d.ts +0 -2
- package/dist/runtime/core/bindings/sharp/wasm.mjs +0 -2
- package/dist/runtime/core/html/fetch.d.ts +0 -3
- package/dist/runtime/nuxt/plugins/nuxt-content-canonical-urls.mjs +0 -29
- package/dist/runtime/public-assets/__nuxt_og_image__/browser-provider-not-supported.png +0 -0
- package/dist/runtime/server/routes/__og-image__/image-[path]-og.[extension].mjs +0 -45
- package/dist/runtime/utilts.d.ts +0 -2
- package/dist/runtime/utilts.mjs +0 -8
- /package/dist/runtime/core/bindings/satori/{yoga-wasm.d.ts → stackblitz.d.ts} +0 -0
- /package/dist/runtime/nuxt/plugins/{nuxt-content-canonical-urls.d.ts → og-image-canonical-urls.server.d.ts} +0 -0
- /package/dist/runtime/{public-assets-optional/inter-font → server/assets}/inter-latin-ext-400-normal.woff +0 -0
- /package/dist/runtime/{public-assets-optional/inter-font → server/assets}/inter-latin-ext-700-normal.woff +0 -0
- /package/dist/runtime/server/routes/__og-image__/{image-[path]-og.[extension].d.ts → image.d.ts} +0 -0
package/dist/module.mjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
-
import { useNuxt, createResolver, addTemplate,
|
|
3
|
+
import { loadNuxtModuleInstance, useNuxt, createResolver, addTemplate, resolvePath, defineNuxtModule, useLogger, hasNuxtModule, addServerPlugin, addServerHandler, addImports, addComponentsDir, addComponent, addPlugin } from '@nuxt/kit';
|
|
4
4
|
import { installNuxtSiteConfig } from 'nuxt-site-config-kit';
|
|
5
|
-
import { provider, env } from 'std-env';
|
|
5
|
+
import { provider, env, isDevelopment } from 'std-env';
|
|
6
6
|
import { hash } from 'ohash';
|
|
7
|
-
import { relative } from 'pathe';
|
|
8
|
-
import 'nypm';
|
|
7
|
+
import { relative, dirname } from 'pathe';
|
|
9
8
|
import { defu } from 'defu';
|
|
9
|
+
import 'nypm';
|
|
10
10
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
11
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
11
13
|
|
|
12
|
-
const version = "3.0.0-beta.
|
|
14
|
+
const version = "3.0.0-beta.40";
|
|
13
15
|
|
|
14
16
|
const autodetectableProviders = {
|
|
15
17
|
azure_static: "azure",
|
|
@@ -32,18 +34,19 @@ const NodeRuntime = {
|
|
|
32
34
|
"resvg": "node",
|
|
33
35
|
"satori": "node",
|
|
34
36
|
"sharp": "node"
|
|
35
|
-
}
|
|
36
|
-
wasmStrategy: "import"
|
|
37
|
+
}
|
|
37
38
|
};
|
|
38
39
|
const cloudflare = {
|
|
39
40
|
bindings: {
|
|
40
41
|
"chromium": false,
|
|
41
|
-
"css-inline":
|
|
42
|
+
"css-inline": false,
|
|
42
43
|
"resvg": "wasm",
|
|
43
44
|
"satori": "node",
|
|
44
45
|
"sharp": false
|
|
45
46
|
},
|
|
46
|
-
|
|
47
|
+
wasm: {
|
|
48
|
+
esmImport: true
|
|
49
|
+
}
|
|
47
50
|
};
|
|
48
51
|
const awsLambda = {
|
|
49
52
|
bindings: {
|
|
@@ -52,8 +55,7 @@ const awsLambda = {
|
|
|
52
55
|
"resvg": "node",
|
|
53
56
|
"satori": "node",
|
|
54
57
|
"sharp": "node"
|
|
55
|
-
}
|
|
56
|
-
wasmStrategy: "inline"
|
|
58
|
+
}
|
|
57
59
|
};
|
|
58
60
|
const RuntimeCompatibility = {
|
|
59
61
|
"nitro-dev": NodeRuntime,
|
|
@@ -62,45 +64,43 @@ const RuntimeCompatibility = {
|
|
|
62
64
|
"stackblitz": {
|
|
63
65
|
bindings: {
|
|
64
66
|
"chromium": false,
|
|
65
|
-
"css-inline":
|
|
66
|
-
"resvg": "
|
|
67
|
-
"satori": "
|
|
68
|
-
"sharp":
|
|
69
|
-
}
|
|
70
|
-
wasmStrategy: "inline"
|
|
67
|
+
"css-inline": false,
|
|
68
|
+
"resvg": "stackblitz",
|
|
69
|
+
"satori": "stackblitz",
|
|
70
|
+
"sharp": false
|
|
71
|
+
}
|
|
71
72
|
},
|
|
72
73
|
"aws-lambda": awsLambda,
|
|
73
74
|
"netlify": awsLambda,
|
|
74
75
|
"netlify-edge": {
|
|
75
76
|
bindings: {
|
|
76
77
|
"chromium": false,
|
|
77
|
-
"css-inline":
|
|
78
|
-
"resvg": "node",
|
|
79
|
-
"satori": "node",
|
|
80
|
-
"sharp": false
|
|
81
|
-
},
|
|
82
|
-
wasmStrategy: "inline"
|
|
83
|
-
},
|
|
84
|
-
"vercel": {
|
|
85
|
-
bindings: {
|
|
86
|
-
"chromium": false,
|
|
87
|
-
"css-inline": "node",
|
|
78
|
+
"css-inline": false,
|
|
88
79
|
"resvg": "wasm",
|
|
89
80
|
"satori": "node",
|
|
90
|
-
"sharp":
|
|
81
|
+
"sharp": false
|
|
91
82
|
},
|
|
92
|
-
|
|
83
|
+
wasm: {
|
|
84
|
+
rollup: {
|
|
85
|
+
targetEnv: "auto-inline",
|
|
86
|
+
sync: ["@resvg/resvg-wasm/index_bg.wasm"]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
93
89
|
},
|
|
90
|
+
"firebase": awsLambda,
|
|
91
|
+
"vercel": awsLambda,
|
|
94
92
|
"vercel-edge": {
|
|
95
93
|
bindings: {
|
|
96
94
|
"chromium": false,
|
|
97
|
-
"css-inline":
|
|
95
|
+
"css-inline": false,
|
|
98
96
|
"resvg": "wasm",
|
|
99
97
|
"satori": "node",
|
|
100
|
-
"sharp":
|
|
98
|
+
"sharp": false
|
|
101
99
|
},
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
wasm: {
|
|
101
|
+
// lowers workers kb size
|
|
102
|
+
esmImport: true
|
|
103
|
+
}
|
|
104
104
|
},
|
|
105
105
|
"cloudflare-pages": cloudflare,
|
|
106
106
|
"cloudflare": cloudflare
|
|
@@ -141,15 +141,37 @@ function applyNitroPresetCompatibility(nitroConfig, options) {
|
|
|
141
141
|
applyBinding("satori"),
|
|
142
142
|
applyBinding("resvg"),
|
|
143
143
|
applyBinding("sharp"),
|
|
144
|
+
applyBinding("css-inline"),
|
|
144
145
|
nitroConfig.alias || {}
|
|
145
146
|
);
|
|
146
|
-
if (
|
|
147
|
-
nitroConfig.
|
|
148
|
-
nitroConfig.
|
|
147
|
+
if (Object.values(compatibility.bindings).includes("wasm")) {
|
|
148
|
+
nitroConfig.experimental = nitroConfig.experimental || {};
|
|
149
|
+
nitroConfig.experimental.wasm = true;
|
|
149
150
|
}
|
|
151
|
+
nitroConfig.rollupConfig = nitroConfig.rollupConfig || {};
|
|
152
|
+
nitroConfig.wasm = defu(compatibility.wasm, nitroConfig.wasm);
|
|
150
153
|
return compatibility;
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
async function getNuxtModuleOptions(module, nuxt = useNuxt()) {
|
|
157
|
+
const moduleMeta = (typeof module === "string" ? { name: module } : await module.getMeta?.()) || {};
|
|
158
|
+
const { nuxtModule } = await loadNuxtModuleInstance(module, nuxt);
|
|
159
|
+
let moduleEntry;
|
|
160
|
+
for (const m of nuxt.options.modules) {
|
|
161
|
+
if (Array.isArray(m) && m.length >= 2) {
|
|
162
|
+
const _module = m[0];
|
|
163
|
+
const _moduleEntryName = typeof _module === "string" ? _module : (await _module.getMeta?.())?.name || "";
|
|
164
|
+
if (_moduleEntryName === moduleMeta.name)
|
|
165
|
+
moduleEntry = m;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
let inlineOptions = {};
|
|
169
|
+
if (moduleEntry)
|
|
170
|
+
inlineOptions = moduleEntry[1];
|
|
171
|
+
if (nuxtModule.getOptions)
|
|
172
|
+
return nuxtModule.getOptions(inlineOptions, nuxt);
|
|
173
|
+
return inlineOptions;
|
|
174
|
+
}
|
|
153
175
|
function extendTypes(module, template) {
|
|
154
176
|
const nuxt = useNuxt();
|
|
155
177
|
const { resolve } = createResolver(import.meta.url);
|
|
@@ -201,9 +223,15 @@ function setupDevToolsUI(options, resolve, nuxt = useNuxt()) {
|
|
|
201
223
|
rpc.broadcast.refreshRouteData(path).catch(() => {
|
|
202
224
|
});
|
|
203
225
|
}
|
|
204
|
-
if (options.componentDirs.some((dir) => path.includes(dir)))
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
if (options.componentDirs.some((dir) => path.includes(dir))) {
|
|
227
|
+
if (e === "change") {
|
|
228
|
+
rpc.broadcast.refresh().catch(() => {
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
rpc.broadcast.refreshGlobalData().catch(() => {
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
207
235
|
});
|
|
208
236
|
});
|
|
209
237
|
nuxt.hook("devtools:customTabs", (tabs) => {
|
|
@@ -226,8 +254,8 @@ function setupDevToolsUI(options, resolve, nuxt = useNuxt()) {
|
|
|
226
254
|
function setupDevHandler(options, resolve, nuxt = useNuxt()) {
|
|
227
255
|
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
228
256
|
nitroConfig.alias["#nuxt-og-image/renderers/satori"] = options.runtimeSatori ? resolve("./runtime/core/renderers/satori") : "unenv/runtime/mock/empty";
|
|
229
|
-
nitroConfig.alias["#nuxt-og-image/renderers/chromium"] = options.
|
|
230
|
-
applyNitroPresetCompatibility(nitroConfig, { resolve });
|
|
257
|
+
nitroConfig.alias["#nuxt-og-image/renderers/chromium"] = options.runtimeChromium ? resolve("./runtime/core/renderers/chromium") : "unenv/runtime/mock/empty";
|
|
258
|
+
applyNitroPresetCompatibility(nitroConfig, { resolve, compatibility: options.runtimeCompatibility });
|
|
231
259
|
});
|
|
232
260
|
}
|
|
233
261
|
|
|
@@ -251,12 +279,13 @@ function setupGenerateHandler(options, resolve, nuxt = useNuxt()) {
|
|
|
251
279
|
}
|
|
252
280
|
|
|
253
281
|
function setupPrerenderHandler(options, resolve, nuxt = useNuxt()) {
|
|
254
|
-
addServerPlugin(resolve("./runtime/nitro/plugins/prerender.ts"));
|
|
255
282
|
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
256
283
|
nitro.hooks.hook("prerender:config", async (nitroConfig) => {
|
|
257
284
|
nitroConfig.alias["#nuxt-og-image/renderers/satori"] = resolve("./runtime/core/renderers/satori");
|
|
258
285
|
nitroConfig.alias["#nuxt-og-image/renderers/chromium"] = resolve("./runtime/core/renderers/chromium");
|
|
259
286
|
applyNitroPresetCompatibility(nitroConfig, { resolve });
|
|
287
|
+
nitroConfig.wasm = nitroConfig.wasm || {};
|
|
288
|
+
nitroConfig.wasm.esmImport = false;
|
|
260
289
|
});
|
|
261
290
|
});
|
|
262
291
|
}
|
|
@@ -267,20 +296,41 @@ async function setupBuildHandler(config, resolve, nuxt = useNuxt()) {
|
|
|
267
296
|
nuxt.options.nitro.storage["og-image"] = config.runtimeCacheStorage;
|
|
268
297
|
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
269
298
|
nitroConfig.alias["#nuxt-og-image/renderers/satori"] = config.runtimeSatori ? resolve("./runtime/core/renderers/satori") : "unenv/runtime/mock/empty";
|
|
270
|
-
nitroConfig.alias["#nuxt-og-image/renderers/chromium"] = config.
|
|
299
|
+
nitroConfig.alias["#nuxt-og-image/renderers/chromium"] = config.runtimeChromium ? resolve("./runtime/core/renderers/chromium") : "unenv/runtime/mock/empty";
|
|
271
300
|
applyNitroPresetCompatibility(nitroConfig, { resolve, compatibility: config.runtimeCompatibility });
|
|
272
301
|
nitroConfig.alias.electron = "unenv/runtime/mock/proxy-cjs";
|
|
273
302
|
nitroConfig.alias.bufferutil = "unenv/runtime/mock/proxy-cjs";
|
|
274
303
|
nitroConfig.alias["utf-8-validate"] = "unenv/runtime/mock/proxy-cjs";
|
|
275
304
|
nitroConfig.alias.queue = "unenv/runtime/mock/proxy-cjs";
|
|
276
305
|
});
|
|
306
|
+
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
307
|
+
nitro.hooks.hook("compiled", async (_nitro) => {
|
|
308
|
+
const target = resolveNitroPreset(_nitro.options);
|
|
309
|
+
const compatibility = getPresetNitroPresetCompatibility(target);
|
|
310
|
+
if (compatibility.wasm?.esmImport !== true)
|
|
311
|
+
return;
|
|
312
|
+
const configuredEntry = nitro.options.rollupConfig?.output.entryFileNames;
|
|
313
|
+
let serverEntry = resolve(_nitro.options.output.serverDir, typeof configuredEntry === "string" ? configuredEntry : "index.mjs");
|
|
314
|
+
if (target === "cloudflare-pages")
|
|
315
|
+
serverEntry = resolve(dirname(serverEntry), "./chunks/wasm.mjs");
|
|
316
|
+
const contents = await readFile(serverEntry, "utf-8");
|
|
317
|
+
const resvgHash = sha1(await readFile(await resolvePath("@resvg/resvg-wasm/index_bg.wasm")));
|
|
318
|
+
const yogaHash = sha1(await readFile(await resolvePath("yoga-wasm-web/dist/yoga.wasm")));
|
|
319
|
+
const postfix = target === "vercel-edge" ? "?module" : "";
|
|
320
|
+
const path = target === "cloudflare-pages" ? `../wasm/` : `./wasm/`;
|
|
321
|
+
await writeFile(serverEntry, contents.replaceAll('"@resvg/resvg-wasm/index_bg.wasm"', `"${path}index_bg-${resvgHash}.wasm${postfix}"`).replaceAll('"yoga-wasm-web/dist/yoga.wasm"', `"${path}yoga-${yogaHash}.wasm${postfix}"`), { encoding: "utf-8" });
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function sha1(source) {
|
|
326
|
+
return createHash("sha1").update(source).digest("hex").slice(0, 16);
|
|
277
327
|
}
|
|
278
328
|
|
|
279
329
|
const module = defineNuxtModule({
|
|
280
330
|
meta: {
|
|
281
331
|
name: "nuxt-og-image",
|
|
282
332
|
compatibility: {
|
|
283
|
-
nuxt: "^3.
|
|
333
|
+
nuxt: "^3.8.2",
|
|
284
334
|
bridge: false
|
|
285
335
|
},
|
|
286
336
|
configKey: "ogImage"
|
|
@@ -289,21 +339,20 @@ const module = defineNuxtModule({
|
|
|
289
339
|
return {
|
|
290
340
|
enabled: true,
|
|
291
341
|
defaults: {
|
|
342
|
+
emojis: "noto",
|
|
292
343
|
renderer: "satori",
|
|
293
|
-
component: "
|
|
344
|
+
component: "NuxtSeo",
|
|
294
345
|
width: 1200,
|
|
295
346
|
height: 600,
|
|
296
|
-
cache
|
|
297
|
-
|
|
298
|
-
cacheTtl: 24 * 60 * 60 * 1e3
|
|
347
|
+
// default is to cache the image for 3 day (72 hours)
|
|
348
|
+
cacheMaxAgeSeconds: 60 * 60 * 24 * 3
|
|
299
349
|
},
|
|
300
350
|
componentDirs: ["OgImage", "OgImageTemplate"],
|
|
301
|
-
runtimeSatori: true,
|
|
302
|
-
runtimeBrowser: nuxt.options.dev,
|
|
303
351
|
fonts: [],
|
|
304
352
|
runtimeCacheStorage: true,
|
|
305
|
-
|
|
306
|
-
|
|
353
|
+
runtimeSatori: true,
|
|
354
|
+
runtimeChromium: nuxt.options.dev,
|
|
355
|
+
debug: isDevelopment
|
|
307
356
|
};
|
|
308
357
|
},
|
|
309
358
|
async setup(config, nuxt) {
|
|
@@ -320,16 +369,44 @@ const module = defineNuxtModule({
|
|
|
320
369
|
const { resolve } = createResolver(import.meta.url);
|
|
321
370
|
const preset = resolveNitroPreset(nuxt.options.nitro);
|
|
322
371
|
const compatibility = getPresetNitroPresetCompatibility(preset);
|
|
323
|
-
config.defaults.extension
|
|
324
|
-
|
|
372
|
+
const userConfiguredExtension = config.defaults.extension;
|
|
373
|
+
config.defaults.extension = userConfiguredExtension || "jpg";
|
|
374
|
+
if (!compatibility.bindings.sharp && config.defaults.renderer !== "chromium") {
|
|
375
|
+
if (userConfiguredExtension && ["jpeg", "jpg"].includes(userConfiguredExtension))
|
|
376
|
+
logger.warn("The sharp runtime is not available for this target, disabling sharp and using png instead.");
|
|
325
377
|
config.defaults.extension = "png";
|
|
378
|
+
}
|
|
379
|
+
if (config.runtimeChromium && !compatibility.bindings.chromium) {
|
|
380
|
+
logger.warn("The Chromium runtime is not available for this target, disabling runtimeChromium.");
|
|
381
|
+
config.runtimeChromium = false;
|
|
382
|
+
}
|
|
326
383
|
await installNuxtSiteConfig();
|
|
327
|
-
if (hasNuxtModule("@nuxt/content"))
|
|
384
|
+
if (hasNuxtModule("@nuxt/content"))
|
|
328
385
|
addServerPlugin(resolve("./runtime/nitro/plugins/nuxt-content"));
|
|
329
|
-
addPlugin(resolve("./runtime/nuxt/plugins/nuxt-content-canonical-urls"));
|
|
330
|
-
}
|
|
331
386
|
if (!config.fonts.length)
|
|
332
387
|
config.fonts = ["Inter:400", "Inter:700"];
|
|
388
|
+
if (preset === "stackblitz") {
|
|
389
|
+
config.fonts = config.fonts.map((f) => {
|
|
390
|
+
if (typeof f === "string" && f.startsWith("Inter:")) {
|
|
391
|
+
const [_, weight] = f.split(":");
|
|
392
|
+
return {
|
|
393
|
+
name: "Inter",
|
|
394
|
+
weight,
|
|
395
|
+
// nuxt server assets
|
|
396
|
+
key: `nuxt-og-image:fonts:inter-latin-ext-${weight}-normal.woff`
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
if (typeof f === "string" || !f.path && !f.key) {
|
|
400
|
+
logger.warn(`The ${typeof f === "string" ? f : `${f.name}:${f.weight}`} font was skipped because remote fonts are not available in StackBlitz, please use a local font.`);
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
return f;
|
|
404
|
+
}).filter(Boolean);
|
|
405
|
+
nuxt.hooks.hook("nitro:config", (nitroConfig) => {
|
|
406
|
+
nitroConfig.serverAssets = nitroConfig.serverAssets || [];
|
|
407
|
+
nitroConfig.serverAssets.push({ baseName: "nuxt-og-image:fonts", dir: resolve("./runtime/server/assets") });
|
|
408
|
+
});
|
|
409
|
+
}
|
|
333
410
|
nuxt.options.experimental.componentIslands = true;
|
|
334
411
|
addServerHandler({
|
|
335
412
|
lazy: true,
|
|
@@ -346,52 +423,34 @@ const module = defineNuxtModule({
|
|
|
346
423
|
addServerHandler({
|
|
347
424
|
lazy: true,
|
|
348
425
|
route: "/__og-image__/image/**",
|
|
349
|
-
handler: resolve("./runtime/server/routes/__og-image__/image
|
|
426
|
+
handler: resolve("./runtime/server/routes/__og-image__/image")
|
|
350
427
|
});
|
|
351
428
|
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] = [];
|
|
352
|
-
[
|
|
353
|
-
// deprecated
|
|
354
|
-
"Dynamic",
|
|
355
|
-
"Static",
|
|
356
|
-
// new
|
|
357
|
-
"index",
|
|
358
|
-
"Cached",
|
|
359
|
-
"Component",
|
|
360
|
-
"WithoutCache",
|
|
361
|
-
"Screenshot"
|
|
362
|
-
].forEach((name) => {
|
|
363
|
-
name = name === "index" ? "defineOgImage" : `defineOgImage${name}`;
|
|
429
|
+
["defineOgImage", "defineOgImageComponent", "defineOgImageScreenshot"].forEach((name) => {
|
|
364
430
|
addImports({
|
|
365
431
|
name,
|
|
366
|
-
from: resolve(
|
|
432
|
+
from: resolve(`./runtime/composables/${name}`)
|
|
367
433
|
});
|
|
368
434
|
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"].push(name);
|
|
369
435
|
});
|
|
370
436
|
await addComponentsDir({
|
|
371
437
|
path: resolve("./runtime/components/Templates/Community"),
|
|
372
|
-
island: true
|
|
373
|
-
|
|
374
|
-
await addComponentsDir({
|
|
375
|
-
path: resolve("./runtime/components/Templates/Official"),
|
|
376
|
-
island: true
|
|
438
|
+
island: true,
|
|
439
|
+
watch: true
|
|
377
440
|
});
|
|
378
441
|
[
|
|
379
|
-
// deprecated
|
|
380
|
-
"Static",
|
|
381
|
-
"Dynamic",
|
|
382
442
|
// new
|
|
383
|
-
"
|
|
384
|
-
"
|
|
385
|
-
"WithoutCache",
|
|
386
|
-
"Screenshot"
|
|
443
|
+
"OgImage",
|
|
444
|
+
"OgImageScreenshot"
|
|
387
445
|
].forEach((name) => {
|
|
388
446
|
addComponent({
|
|
389
|
-
|
|
390
|
-
|
|
447
|
+
name,
|
|
448
|
+
global: true,
|
|
391
449
|
filePath: resolve(`./runtime/components/OgImage/${name}`)
|
|
392
450
|
});
|
|
393
451
|
});
|
|
394
|
-
addPlugin(resolve("./runtime/nuxt/plugins/route-rule-og-image.server"));
|
|
452
|
+
addPlugin({ mode: "server", src: resolve("./runtime/nuxt/plugins/route-rule-og-image.server") });
|
|
453
|
+
addPlugin({ mode: "server", src: resolve("./runtime/nuxt/plugins/og-image-canonical-urls.server") });
|
|
395
454
|
const ogImageComponentCtx = { components: [] };
|
|
396
455
|
nuxt.hook("components:extend", (components) => {
|
|
397
456
|
ogImageComponentCtx.components = [];
|
|
@@ -409,8 +468,6 @@ const module = defineNuxtModule({
|
|
|
409
468
|
let category = "app";
|
|
410
469
|
if (component.filePath.includes(resolve("./runtime/components/Templates/Community")))
|
|
411
470
|
category = "community";
|
|
412
|
-
else if (component.filePath.includes(resolve("./runtime/components/Templates/Official")))
|
|
413
|
-
category = "official";
|
|
414
471
|
const componentFile = fs.readFileSync(component.filePath, "utf-8");
|
|
415
472
|
const credits = componentFile.split("\n").find((line) => line.startsWith(" * @credits"))?.replace("* @credits", "").trim();
|
|
416
473
|
ogImageComponentCtx.components.push({
|
|
@@ -437,6 +494,16 @@ const module = defineNuxtModule({
|
|
|
437
494
|
nuxt.options.nitro.virtual["#nuxt-og-image/component-names.mjs"] = () => {
|
|
438
495
|
return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}`;
|
|
439
496
|
};
|
|
497
|
+
let unoCssConfig = { theme: {} };
|
|
498
|
+
nuxt.hook("tailwindcss:config", (tailwindConfig) => {
|
|
499
|
+
unoCssConfig = defu(tailwindConfig.theme.extend, { ...tailwindConfig.theme || {}, extend: void 0 });
|
|
500
|
+
});
|
|
501
|
+
nuxt.hook("unocss:config", (_unoCssConfig) => {
|
|
502
|
+
unoCssConfig = { ..._unoCssConfig.theme };
|
|
503
|
+
});
|
|
504
|
+
nuxt.options.nitro.virtual["#nuxt-og-image/unocss-config.mjs"] = () => {
|
|
505
|
+
return `export const theme = ${JSON.stringify(unoCssConfig)}`;
|
|
506
|
+
};
|
|
440
507
|
extendTypes("nuxt-og-image", ({ typesPath }) => {
|
|
441
508
|
const componentImports = ogImageComponentCtx.components.map((component) => {
|
|
442
509
|
const relativeComponentPath = relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), component.path);
|
|
@@ -445,12 +512,13 @@ const module = defineNuxtModule({
|
|
|
445
512
|
return `
|
|
446
513
|
declare module 'nitropack' {
|
|
447
514
|
interface NitroRouteRules {
|
|
448
|
-
ogImage?: false | import('${typesPath}').OgImageOptions
|
|
515
|
+
ogImage?: false | import('${typesPath}').OgImageOptions & Record<string, any>
|
|
449
516
|
}
|
|
450
517
|
interface NitroRouteConfig {
|
|
451
|
-
ogImage?: false | import('${typesPath}').OgImageOptions
|
|
518
|
+
ogImage?: false | import('${typesPath}').OgImageOptions & Record<string, any>
|
|
452
519
|
}
|
|
453
520
|
}
|
|
521
|
+
|
|
454
522
|
declare module '#nuxt-og-image/components' {
|
|
455
523
|
export interface OgImageComponents {
|
|
456
524
|
${componentImports}
|
|
@@ -458,6 +526,11 @@ ${componentImports}
|
|
|
458
526
|
}
|
|
459
527
|
`;
|
|
460
528
|
});
|
|
529
|
+
const cacheEnabled = typeof config.runtimeCacheStorage !== "undefined" && config.runtimeCacheStorage !== false;
|
|
530
|
+
const runtimeCacheStorage = typeof config.runtimeCacheStorage === "boolean" ? "default" : config.runtimeCacheStorage.driver;
|
|
531
|
+
let baseCacheKey = runtimeCacheStorage === "default" ? `/cache/nuxt-og-image@${version}` : `/nuxt-og-image@${version}`;
|
|
532
|
+
if (!cacheEnabled)
|
|
533
|
+
baseCacheKey = false;
|
|
461
534
|
nuxt.hooks.hook("modules:done", async () => {
|
|
462
535
|
nuxt.hooks.callHook("og-image:config", config);
|
|
463
536
|
const normalisedFonts = config.fonts.map((f) => {
|
|
@@ -474,10 +547,13 @@ ${componentImports}
|
|
|
474
547
|
if (!nuxt.options._generate && nuxt.options.build) {
|
|
475
548
|
nuxt.options.nitro.prerender = nuxt.options.nitro.prerender || {};
|
|
476
549
|
nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes || [];
|
|
477
|
-
normalisedFonts.filter((f) => !f.path).forEach(({ name, weight }) => {
|
|
550
|
+
normalisedFonts.filter((f) => !f.path && !f.key).forEach(({ name, weight }) => {
|
|
478
551
|
nuxt.options.nitro.prerender.routes.push(`/__og-image__/font/${name}/${weight}.ttf`);
|
|
479
552
|
});
|
|
480
553
|
}
|
|
554
|
+
let colorPreference = hasNuxtModule("@nuxtjs/color-mode") ? (await getNuxtModuleOptions("@nuxtjs/color-mode")).preference : "light";
|
|
555
|
+
if (!colorPreference || !["dark", "light"].includes(colorPreference))
|
|
556
|
+
colorPreference = "light";
|
|
481
557
|
nuxt.options.runtimeConfig["nuxt-og-image"] = {
|
|
482
558
|
version,
|
|
483
559
|
// binding options
|
|
@@ -485,18 +561,17 @@ ${componentImports}
|
|
|
485
561
|
resvgOptions: config.resvgOptions || {},
|
|
486
562
|
sharpOptions: config.sharpOptions || {},
|
|
487
563
|
runtimeSatori: config.runtimeSatori,
|
|
488
|
-
|
|
489
|
-
// @ts-expect-error runtime type
|
|
564
|
+
runtimeChromium: config.runtimeChromium,
|
|
490
565
|
defaults: config.defaults,
|
|
566
|
+
debug: config.debug,
|
|
491
567
|
// avoid adding credentials
|
|
492
|
-
|
|
568
|
+
baseCacheKey,
|
|
493
569
|
// convert the fonts to uniform type to fix ts issue
|
|
494
570
|
fonts: normalisedFonts,
|
|
495
|
-
hasNuxtIcon: hasNuxtModule("nuxt-icon")
|
|
571
|
+
hasNuxtIcon: hasNuxtModule("nuxt-icon"),
|
|
572
|
+
colorPreference
|
|
496
573
|
};
|
|
497
574
|
});
|
|
498
|
-
nuxt.options.nitro.experimental = nuxt.options.nitro.experimental || {};
|
|
499
|
-
nuxt.options.nitro.experimental.wasm = true;
|
|
500
575
|
if (nuxt.options.dev) {
|
|
501
576
|
setupDevHandler(config, resolve);
|
|
502
577
|
setupDevToolsUI(config, resolve);
|
|
@@ -505,8 +580,9 @@ ${componentImports}
|
|
|
505
580
|
} else if (nuxt.options.build) {
|
|
506
581
|
await setupBuildHandler(config, resolve);
|
|
507
582
|
}
|
|
508
|
-
if (nuxt.options.
|
|
509
|
-
|
|
583
|
+
if (nuxt.options.build)
|
|
584
|
+
addServerPlugin(resolve("./runtime/nitro/plugins/prerender"));
|
|
585
|
+
setupPrerenderHandler(config, resolve);
|
|
510
586
|
}
|
|
511
587
|
});
|
|
512
588
|
|
package/dist/runtime/cache.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
skipRestore?: boolean;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
cachedItem: false | T;
|
|
1
|
+
import type { H3EventOgImageRender } from './types';
|
|
2
|
+
export declare function useOgImageBufferCache(ctx: H3EventOgImageRender, options: {
|
|
3
|
+
baseCacheKey: string | false;
|
|
4
|
+
cacheMaxAgeSeconds?: number;
|
|
5
|
+
}): Promise<void | {
|
|
6
|
+
cachedItem: false | BufferSource;
|
|
10
7
|
enabled: boolean;
|
|
11
|
-
update: (
|
|
8
|
+
update: (image: BufferSource) => Promise<void>;
|
|
12
9
|
}>;
|
package/dist/runtime/cache.mjs
CHANGED
|
@@ -1,45 +1,58 @@
|
|
|
1
1
|
import { prefixStorage } from "unstorage";
|
|
2
|
-
import { getQuery, setHeader } from "h3";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const cache = prefixStorage(useStorage(),
|
|
10
|
-
const key =
|
|
11
|
-
let xCacheHeader = "DISABLED";
|
|
12
|
-
let xCacheExpires = 0;
|
|
13
|
-
const newExpires = Date.now() + (options.cacheTtl || 0);
|
|
14
|
-
const purge = typeof getQuery(e).purge !== "undefined";
|
|
2
|
+
import { getQuery, handleCacheHeaders, setHeader, setHeaders } from "h3";
|
|
3
|
+
import { withTrailingSlash } from "ufo";
|
|
4
|
+
import { hash } from "ohash";
|
|
5
|
+
import { useStorage } from "#imports";
|
|
6
|
+
export async function useOgImageBufferCache(ctx, options) {
|
|
7
|
+
const maxAge = Number(options.cacheMaxAgeSeconds);
|
|
8
|
+
const enabled = !import.meta.dev && import.meta.env.MODE !== "test" && maxAge > 0;
|
|
9
|
+
const cache = prefixStorage(useStorage(), withTrailingSlash(options.baseCacheKey || "/"));
|
|
10
|
+
const key = ctx.key;
|
|
15
11
|
let cachedItem = false;
|
|
16
|
-
if (
|
|
17
|
-
const { value, expiresAt } = await cache.getItem(key).catch(() => ({ value: null, expiresAt: Date.now() }));
|
|
18
|
-
if (purge) {
|
|
19
|
-
xCacheHeader = "PURGE";
|
|
20
|
-
xCacheExpires = newExpires;
|
|
12
|
+
if (enabled && await cache.hasItem(key).catch(() => false)) {
|
|
13
|
+
const { value, expiresAt, headers } = await cache.getItem(key).catch(() => ({ value: null, expiresAt: Date.now() }));
|
|
14
|
+
if (typeof getQuery(ctx.e).purge !== "undefined") {
|
|
21
15
|
await cache.removeItem(key).catch(() => {
|
|
22
16
|
});
|
|
23
17
|
} else if (expiresAt > Date.now()) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
cachedItem = Buffer.from(value, "base64");
|
|
19
|
+
if (handleCacheHeaders(ctx.e, {
|
|
20
|
+
modifiedTime: new Date(headers["last-modified"]),
|
|
21
|
+
etag: headers.etag,
|
|
22
|
+
maxAge
|
|
23
|
+
}))
|
|
24
|
+
return;
|
|
25
|
+
setHeaders(ctx.e, headers);
|
|
27
26
|
} else {
|
|
28
|
-
xCacheHeader = "MISS";
|
|
29
|
-
xCacheExpires = expiresAt;
|
|
30
27
|
await cache.removeItem(key).catch(() => {
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
if (
|
|
35
|
-
setHeader(e,
|
|
36
|
-
setHeader(e,
|
|
31
|
+
if (!enabled) {
|
|
32
|
+
setHeader(ctx.e, "Cache-Control", "no-cache, no-store, must-revalidate");
|
|
33
|
+
setHeader(ctx.e, "Pragma", "no-cache");
|
|
34
|
+
setHeader(ctx.e, "Expires", "0");
|
|
37
35
|
}
|
|
38
36
|
return {
|
|
39
37
|
enabled,
|
|
40
38
|
cachedItem,
|
|
41
39
|
async update(item) {
|
|
42
|
-
|
|
40
|
+
if (!enabled)
|
|
41
|
+
return;
|
|
42
|
+
const value = Buffer.from(item).toString("base64");
|
|
43
|
+
const headers = {
|
|
44
|
+
// avoid multi-tenancy cache issues
|
|
45
|
+
"Vary": "accept-encoding, host",
|
|
46
|
+
"etag": `W/"${hash(value)}"`,
|
|
47
|
+
"last-modified": (/* @__PURE__ */ new Date()).toUTCString(),
|
|
48
|
+
"cache-control": `public, s-maxage=${maxAge}, stale-while-revalidate`
|
|
49
|
+
};
|
|
50
|
+
setHeaders(ctx.e, headers);
|
|
51
|
+
await cache.setItem(key, {
|
|
52
|
+
value,
|
|
53
|
+
headers,
|
|
54
|
+
expiresAt: Date.now() + maxAge * 1e3
|
|
55
|
+
});
|
|
43
56
|
}
|
|
44
57
|
};
|
|
45
58
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OgImageOptions } from '../../types';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<OgImageOptions<"NuxtSeo">, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<OgImageOptions<"NuxtSeo">>, {
|
|
3
|
+
props?: any;
|
|
4
|
+
}, {}>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OgImagePageScreenshotOptions } from '../../types';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<OgImagePageScreenshotOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<OgImagePageScreenshotOptions>, {
|
|
3
|
+
props?: any;
|
|
4
|
+
}, {}>;
|
|
5
|
+
export default _default;
|