nuxt-og-image 4.0.3 → 4.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/content.d.ts +1 -0
- package/dist/client/200.html +8 -8
- package/dist/client/404.html +8 -8
- package/dist/client/_nuxt/{C-_Zqo7-.js → 4XBoJZZ4.js} +3 -3
- package/dist/client/_nuxt/{DB6BmnZb.js → B-MI_7-y.js} +1 -1
- package/dist/client/_nuxt/{BLDCaNbg.js → B2vK47Ag.js} +1 -1
- package/dist/client/_nuxt/{BEqZJfBF.js → BXWLJovA.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/0b18fa5c-2b3e-4e01-b027-788d37db3ec5.json +1 -0
- package/dist/client/_nuxt/error-404.CeB15F3i.css +1 -0
- package/dist/client/_nuxt/error-500.kWwbyTjN.css +1 -0
- package/dist/client/index.html +8 -8
- package/dist/content.cjs +20 -0
- package/dist/content.d.cts +35 -0
- package/dist/content.d.mts +35 -0
- package/dist/content.d.ts +35 -0
- package/dist/content.mjs +17 -0
- package/dist/module.cjs +944 -4
- package/dist/module.d.cts +108 -0
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -3
- package/dist/runtime/types.d.ts +0 -1
- package/package.json +35 -37
- package/dist/client/_nuxt/builds/meta/1ef0ae85-3c8a-4505-a09a-e29f0083c0f4.json +0 -1
- package/dist/client/_nuxt/error-404.CnNYq3i9.css +0 -1
- package/dist/client/_nuxt/error-500.BlU6WHQT.css +0 -1
- /package/dist/runtime/server/plugins/{nuxt-content.d.ts → nuxt-content-v2.d.ts} +0 -0
- /package/dist/runtime/server/plugins/{nuxt-content.js → nuxt-content-v2.js} +0 -0
package/dist/module.cjs
CHANGED
|
@@ -1,5 +1,945 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const promises = require('node:fs/promises');
|
|
5
|
+
const kit = require('@nuxt/kit');
|
|
6
|
+
const defu = require('defu');
|
|
7
|
+
const kit$1 = require('nuxt-site-config/kit');
|
|
8
|
+
const ohash = require('ohash');
|
|
9
|
+
const pathe = require('pathe');
|
|
10
|
+
const pkgTypes = require('pkg-types');
|
|
11
|
+
const stdEnv = require('std-env');
|
|
12
|
+
const ufo = require('ufo');
|
|
13
|
+
const unstorage = require('unstorage');
|
|
14
|
+
const fsDriver = require('unstorage/drivers/fs');
|
|
15
|
+
const node_crypto = require('node:crypto');
|
|
16
|
+
const nypm = require('nypm');
|
|
17
|
+
const node_path = require('node:path');
|
|
18
|
+
const devtoolsKit = require('@nuxt/devtools-kit');
|
|
19
|
+
const node_url = require('node:url');
|
|
20
|
+
const MagicString = require('magic-string');
|
|
21
|
+
const stripLiteral = require('strip-literal');
|
|
22
|
+
const unplugin = require('unplugin');
|
|
23
|
+
const logger_js = require('../dist/runtime/logger.js');
|
|
24
|
+
const chromeLauncher = require('chrome-launcher');
|
|
25
|
+
const ofetch = require('ofetch');
|
|
26
|
+
|
|
27
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
28
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
29
|
+
|
|
30
|
+
function _interopNamespaceCompat(e) {
|
|
31
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
32
|
+
const n = Object.create(null);
|
|
33
|
+
if (e) {
|
|
34
|
+
for (const k in e) {
|
|
35
|
+
n[k] = e[k];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
n.default = e;
|
|
39
|
+
return n;
|
|
3
40
|
}
|
|
4
|
-
|
|
5
|
-
|
|
41
|
+
|
|
42
|
+
const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
43
|
+
const fsDriver__default = /*#__PURE__*/_interopDefaultCompat(fsDriver);
|
|
44
|
+
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
45
|
+
|
|
46
|
+
const autodetectableProviders = {
|
|
47
|
+
azure_static: "azure",
|
|
48
|
+
cloudflare_pages: "cloudflare-pages",
|
|
49
|
+
netlify: "netlify",
|
|
50
|
+
stormkit: "stormkit",
|
|
51
|
+
vercel: "vercel",
|
|
52
|
+
cleavr: "cleavr",
|
|
53
|
+
stackblitz: "stackblitz"
|
|
54
|
+
};
|
|
55
|
+
const autodetectableStaticProviders = {
|
|
56
|
+
netlify: "netlify-static",
|
|
57
|
+
vercel: "vercel-static"
|
|
58
|
+
};
|
|
59
|
+
const NodeRuntime = {
|
|
60
|
+
// node-server runtime
|
|
61
|
+
"chromium": "on-demand",
|
|
62
|
+
// this gets changed build start
|
|
63
|
+
"css-inline": "node",
|
|
64
|
+
"resvg": "node",
|
|
65
|
+
"satori": "node",
|
|
66
|
+
"sharp": "node"
|
|
67
|
+
// will be disabled if they're missing the dependency
|
|
68
|
+
};
|
|
69
|
+
const cloudflare = {
|
|
70
|
+
"chromium": false,
|
|
71
|
+
"css-inline": false,
|
|
72
|
+
"resvg": "wasm",
|
|
73
|
+
"satori": "node",
|
|
74
|
+
"sharp": false,
|
|
75
|
+
"wasm": {
|
|
76
|
+
esmImport: true,
|
|
77
|
+
lazy: true
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const awsLambda = {
|
|
81
|
+
"chromium": false,
|
|
82
|
+
"css-inline": "wasm",
|
|
83
|
+
"resvg": "node",
|
|
84
|
+
"satori": "node",
|
|
85
|
+
"sharp": false
|
|
86
|
+
// 0.33.x has issues
|
|
87
|
+
};
|
|
88
|
+
const WebContainer = {
|
|
89
|
+
"chromium": false,
|
|
90
|
+
"css-inline": "wasm-fs",
|
|
91
|
+
"resvg": "wasm-fs",
|
|
92
|
+
"satori": "wasm-fs",
|
|
93
|
+
"sharp": false
|
|
94
|
+
};
|
|
95
|
+
const RuntimeCompatibility = {
|
|
96
|
+
"nitro-dev": NodeRuntime,
|
|
97
|
+
"nitro-prerender": NodeRuntime,
|
|
98
|
+
"node-server": NodeRuntime,
|
|
99
|
+
"stackblitz": WebContainer,
|
|
100
|
+
"codesandbox": WebContainer,
|
|
101
|
+
"aws-lambda": awsLambda,
|
|
102
|
+
"netlify": awsLambda,
|
|
103
|
+
"netlify-edge": {
|
|
104
|
+
"chromium": false,
|
|
105
|
+
"css-inline": "wasm",
|
|
106
|
+
"resvg": "wasm",
|
|
107
|
+
"satori": "node",
|
|
108
|
+
"sharp": false,
|
|
109
|
+
"wasm": {
|
|
110
|
+
rollup: {
|
|
111
|
+
targetEnv: "auto-inline",
|
|
112
|
+
sync: ["@resvg/resvg-wasm/index_bg.wasm"]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"firebase": awsLambda,
|
|
117
|
+
"vercel": awsLambda,
|
|
118
|
+
"vercel-edge": {
|
|
119
|
+
"chromium": false,
|
|
120
|
+
"css-inline": false,
|
|
121
|
+
// size constraint (2mb is max)
|
|
122
|
+
"resvg": "wasm",
|
|
123
|
+
"satori": "node",
|
|
124
|
+
"sharp": false,
|
|
125
|
+
"wasm": {
|
|
126
|
+
// lowers workers kb size
|
|
127
|
+
esmImport: true,
|
|
128
|
+
lazy: true
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"cloudflare-pages": cloudflare,
|
|
132
|
+
"cloudflare": cloudflare,
|
|
133
|
+
"cloudflare-module": cloudflare
|
|
134
|
+
};
|
|
135
|
+
function detectTarget(options = {}) {
|
|
136
|
+
return options?.static ? autodetectableStaticProviders[stdEnv.provider] : autodetectableProviders[stdEnv.provider];
|
|
137
|
+
}
|
|
138
|
+
function resolveNitroPreset(nitroConfig) {
|
|
139
|
+
if (stdEnv.provider === "stackblitz" || stdEnv.provider === "codesandbox")
|
|
140
|
+
return stdEnv.provider;
|
|
141
|
+
const nuxt = kit.useNuxt();
|
|
142
|
+
if (nuxt.options.dev)
|
|
143
|
+
return "nitro-dev";
|
|
144
|
+
if (nuxt.options._generate)
|
|
145
|
+
return "nitro-prerender";
|
|
146
|
+
let preset;
|
|
147
|
+
if (nitroConfig && nitroConfig?.preset)
|
|
148
|
+
preset = nitroConfig.preset;
|
|
149
|
+
if (!preset)
|
|
150
|
+
preset = stdEnv.env.NITRO_PRESET || stdEnv.env.SERVER_PRESET || detectTarget() || "node-server";
|
|
151
|
+
return preset.replace("_", "-");
|
|
152
|
+
}
|
|
153
|
+
function getPresetNitroPresetCompatibility(target) {
|
|
154
|
+
let compatibility = RuntimeCompatibility[target];
|
|
155
|
+
if (!compatibility)
|
|
156
|
+
compatibility = RuntimeCompatibility["nitro-dev"];
|
|
157
|
+
return compatibility;
|
|
158
|
+
}
|
|
159
|
+
async function applyNitroPresetCompatibility(nitroConfig, options) {
|
|
160
|
+
const target = resolveNitroPreset(nitroConfig);
|
|
161
|
+
const compatibility = getPresetNitroPresetCompatibility(target);
|
|
162
|
+
const hasCssInlineNode = !!await kit.tryResolveModule("@css-inline/css-inline");
|
|
163
|
+
const hasCssInlineWasm = !!await kit.tryResolveModule("@css-inline/css-inline-wasm");
|
|
164
|
+
const { resolve } = options;
|
|
165
|
+
const satoriEnabled = typeof options.compatibility?.satori !== "undefined" ? !!options.compatibility.satori : !!compatibility.satori;
|
|
166
|
+
const chromiumEnabled = typeof options.compatibility?.chromium !== "undefined" ? !!options.compatibility.chromium : !!compatibility.chromium;
|
|
167
|
+
nitroConfig.alias["#og-image/renderers/satori"] = satoriEnabled ? resolve("./runtime/server/og-image/satori/renderer") : "unenv/runtime/mock/empty";
|
|
168
|
+
nitroConfig.alias["#og-image/renderers/chromium"] = chromiumEnabled ? resolve("./runtime/server/og-image/chromium/renderer") : "unenv/runtime/mock/empty";
|
|
169
|
+
const resolvedCompatibility = {};
|
|
170
|
+
function applyBinding(key) {
|
|
171
|
+
let binding = options.compatibility?.[key];
|
|
172
|
+
if (typeof binding === "undefined")
|
|
173
|
+
binding = compatibility[key];
|
|
174
|
+
if (key === "chromium" && binding === "node")
|
|
175
|
+
binding = "playwright";
|
|
176
|
+
if (key === "css-inline" && typeof binding === "string") {
|
|
177
|
+
if (binding === "node" && !hasCssInlineNode || ["wasm", "wasm-fs"].includes(binding) && !hasCssInlineWasm) {
|
|
178
|
+
binding = false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
resolvedCompatibility[key] = binding;
|
|
182
|
+
return {
|
|
183
|
+
[`#og-image/bindings/${key}`]: binding === false ? "unenv/runtime/mock/empty" : resolve(`./runtime/server/og-image/bindings/${key}/${binding}`)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
nitroConfig.alias = defu.defu(
|
|
187
|
+
applyBinding("chromium"),
|
|
188
|
+
applyBinding("satori"),
|
|
189
|
+
applyBinding("resvg"),
|
|
190
|
+
applyBinding("sharp"),
|
|
191
|
+
applyBinding("css-inline"),
|
|
192
|
+
nitroConfig.alias || {}
|
|
193
|
+
);
|
|
194
|
+
if (Object.values(compatibility).includes("wasm")) {
|
|
195
|
+
nitroConfig.experimental = nitroConfig.experimental || {};
|
|
196
|
+
nitroConfig.experimental.wasm = true;
|
|
197
|
+
}
|
|
198
|
+
nitroConfig.rollupConfig = nitroConfig.rollupConfig || {};
|
|
199
|
+
nitroConfig.wasm = defu.defu(compatibility.wasm, nitroConfig.wasm);
|
|
200
|
+
nitroConfig.virtual["#og-image/compatibility"] = () => `export default ${JSON.stringify(resolvedCompatibility)}`;
|
|
201
|
+
kit.addTemplate({
|
|
202
|
+
filename: "nuxt-og-image/compatibility.mjs",
|
|
203
|
+
getContents() {
|
|
204
|
+
return `export default ${JSON.stringify(resolvedCompatibility)}`;
|
|
205
|
+
},
|
|
206
|
+
options: { mode: "server" }
|
|
207
|
+
});
|
|
208
|
+
return resolvedCompatibility;
|
|
209
|
+
}
|
|
210
|
+
function ensureDependencies(dep, nuxt = kit.useNuxt()) {
|
|
211
|
+
return Promise.all(dep.map((d) => {
|
|
212
|
+
return nypm.ensureDependencyInstalled(d, {
|
|
213
|
+
cwd: nuxt.options.rootDir,
|
|
214
|
+
dev: true
|
|
215
|
+
});
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function setupBuildHandler(config, resolve, nuxt = kit.useNuxt()) {
|
|
220
|
+
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
221
|
+
if (typeof config.runtimeCacheStorage === "object")
|
|
222
|
+
nuxt.options.nitro.storage["og-image"] = config.runtimeCacheStorage;
|
|
223
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
224
|
+
await applyNitroPresetCompatibility(nitroConfig, { compatibility: config.compatibility?.runtime, resolve });
|
|
225
|
+
nitroConfig.alias.electron = "unenv/runtime/mock/proxy-cjs";
|
|
226
|
+
nitroConfig.alias.bufferutil = "unenv/runtime/mock/proxy-cjs";
|
|
227
|
+
nitroConfig.alias["utf-8-validate"] = "unenv/runtime/mock/proxy-cjs";
|
|
228
|
+
nitroConfig.alias.queue = "unenv/runtime/mock/proxy-cjs";
|
|
229
|
+
nitroConfig.alias["chromium-bidi"] = "unenv/runtime/mock/proxy-cjs";
|
|
230
|
+
});
|
|
231
|
+
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
232
|
+
const target = resolveNitroPreset(nitro.options);
|
|
233
|
+
const isCloudflarePagesOrModule = target === "cloudflare-pages" || target === "cloudflare-module";
|
|
234
|
+
if (isCloudflarePagesOrModule) {
|
|
235
|
+
nitro.options.cloudflare = nitro.options.cloudflare || {};
|
|
236
|
+
nitro.options.cloudflare.pages = nitro.options.cloudflare.pages || {};
|
|
237
|
+
nitro.options.cloudflare.pages.routes = nitro.options.cloudflare.pages.routes || { exclude: [] };
|
|
238
|
+
nitro.options.cloudflare.pages.routes.exclude = nitro.options.cloudflare.pages.routes.exclude || [];
|
|
239
|
+
nitro.options.cloudflare.pages.routes.exclude.push("/__og-image__/static/*");
|
|
240
|
+
}
|
|
241
|
+
nitro.hooks.hook("compiled", async (_nitro) => {
|
|
242
|
+
const compatibility = getPresetNitroPresetCompatibility(target);
|
|
243
|
+
if (compatibility.wasm?.esmImport !== true)
|
|
244
|
+
return;
|
|
245
|
+
const configuredEntry = nitro.options.rollupConfig?.output.entryFileNames;
|
|
246
|
+
const serverEntry = resolve(_nitro.options.output.serverDir, typeof configuredEntry === "string" ? configuredEntry : "index.mjs");
|
|
247
|
+
const wasmEntries = [serverEntry];
|
|
248
|
+
if (isCloudflarePagesOrModule) {
|
|
249
|
+
wasmEntries.push(resolve(pathe.dirname(serverEntry), "./chunks/wasm.mjs"));
|
|
250
|
+
wasmEntries.push(resolve(pathe.dirname(serverEntry), "./chunks/_/wasm.mjs"));
|
|
251
|
+
wasmEntries.push(resolve(pathe.dirname(serverEntry), "./chunks/index_bg.mjs"));
|
|
252
|
+
}
|
|
253
|
+
const resvgHash = await resolveFilePathSha1("@resvg/resvg-wasm/index_bg.wasm");
|
|
254
|
+
const yogaHash = await resolveFilePathSha1("yoga-wasm-web/dist/yoga.wasm");
|
|
255
|
+
const cssInlineHash = await resolveFilePathSha1("@css-inline/css-inline-wasm/index_bg.wasm");
|
|
256
|
+
for (const entry of wasmEntries) {
|
|
257
|
+
if (!fs.existsSync(entry))
|
|
258
|
+
continue;
|
|
259
|
+
const contents = await promises.readFile(serverEntry, "utf-8");
|
|
260
|
+
const postfix = target === "vercel-edge" ? "?module" : "";
|
|
261
|
+
const path = isCloudflarePagesOrModule ? `../wasm/` : `./wasm/`;
|
|
262
|
+
await promises.writeFile(serverEntry, contents.replaceAll('"@resvg/resvg-wasm/index_bg.wasm?module"', `"${path}index_bg-${resvgHash}.wasm${postfix}"`).replaceAll('"@css-inline/css-inline-wasm/index_bg.wasm?module"', `"${path}index_bg-${cssInlineHash}.wasm${postfix}"`).replaceAll('"yoga-wasm-web/dist/yoga.wasm?module"', `"${path}yoga-${yogaHash}.wasm${postfix}"`), { encoding: "utf-8" });
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
async function resolveFilePathSha1(path) {
|
|
268
|
+
const _path = await kit.resolvePath(path);
|
|
269
|
+
return sha1(fs.existsSync(_path) ? await promises.readFile(_path) : path);
|
|
270
|
+
}
|
|
271
|
+
function sha1(source) {
|
|
272
|
+
return node_crypto.createHash("sha1").update(source).digest("hex").slice(0, 16);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function setupDevHandler(options, resolve, nuxt = kit.useNuxt()) {
|
|
276
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
277
|
+
await applyNitroPresetCompatibility(nitroConfig, { compatibility: options.compatibility?.dev, resolve });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const DEVTOOLS_UI_ROUTE = "/__nuxt-og-image";
|
|
282
|
+
const DEVTOOLS_UI_LOCAL_PORT = 3030;
|
|
283
|
+
function setupDevToolsUI(options, resolve, nuxt = kit.useNuxt()) {
|
|
284
|
+
const clientPath = resolve("./client");
|
|
285
|
+
const isProductionBuild = fs.existsSync(clientPath);
|
|
286
|
+
if (isProductionBuild) {
|
|
287
|
+
nuxt.hook("vite:serverCreated", async (server) => {
|
|
288
|
+
const sirv = await import('sirv').then((r) => r.default || r);
|
|
289
|
+
server.middlewares.use(
|
|
290
|
+
DEVTOOLS_UI_ROUTE,
|
|
291
|
+
sirv(clientPath, { dev: true, single: true })
|
|
292
|
+
);
|
|
293
|
+
});
|
|
294
|
+
} else {
|
|
295
|
+
nuxt.hook("vite:extendConfig", (config) => {
|
|
296
|
+
config.server = config.server || {};
|
|
297
|
+
config.server.proxy = config.server.proxy || {};
|
|
298
|
+
config.server.proxy[DEVTOOLS_UI_ROUTE] = {
|
|
299
|
+
target: `http://localhost:${DEVTOOLS_UI_LOCAL_PORT}${DEVTOOLS_UI_ROUTE}`,
|
|
300
|
+
changeOrigin: true,
|
|
301
|
+
followRedirects: true,
|
|
302
|
+
rewrite: (path) => path.replace(DEVTOOLS_UI_ROUTE, "")
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
devtoolsKit.onDevToolsInitialized(async () => {
|
|
307
|
+
const rpc = devtoolsKit.extendServerRpc("nuxt-og-image", {});
|
|
308
|
+
nuxt.hook("builder:watch", (e, path) => {
|
|
309
|
+
path = node_path.relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, path));
|
|
310
|
+
if ((e === "change" || e.includes("link")) && (path.startsWith("pages") || path.startsWith("content"))) {
|
|
311
|
+
rpc.broadcast.refreshRouteData(path).catch(() => {
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (options.componentDirs.some((dir) => path.includes(dir))) {
|
|
315
|
+
if (e === "change") {
|
|
316
|
+
rpc.broadcast.refresh().catch(() => {
|
|
317
|
+
});
|
|
318
|
+
} else {
|
|
319
|
+
rpc.broadcast.refreshGlobalData().catch(() => {
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
nuxt.hook("devtools:customTabs", (tabs) => {
|
|
326
|
+
tabs.push({
|
|
327
|
+
// unique identifier
|
|
328
|
+
name: "nuxt-og-image",
|
|
329
|
+
// title to display in the tab
|
|
330
|
+
title: "OG Image",
|
|
331
|
+
// any icon from Iconify, or a URL to an image
|
|
332
|
+
icon: "carbon:image-search",
|
|
333
|
+
// iframe view
|
|
334
|
+
view: {
|
|
335
|
+
type: "iframe",
|
|
336
|
+
src: DEVTOOLS_UI_ROUTE
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function setupGenerateHandler(options, resolve, nuxt = kit.useNuxt()) {
|
|
343
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
344
|
+
await applyNitroPresetCompatibility(nitroConfig, {
|
|
345
|
+
compatibility: {
|
|
346
|
+
"chromium": false,
|
|
347
|
+
"satori": false,
|
|
348
|
+
"css-inline": false,
|
|
349
|
+
"resvg": false,
|
|
350
|
+
"sharp": false
|
|
351
|
+
},
|
|
352
|
+
resolve
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function setupPrerenderHandler(options, resolve, nuxt = kit.useNuxt()) {
|
|
358
|
+
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
359
|
+
nitro.hooks.hook("prerender:config", async (nitroConfig) => {
|
|
360
|
+
await applyNitroPresetCompatibility(nitroConfig, { compatibility: options.compatibility?.prerender, resolve });
|
|
361
|
+
nitroConfig.wasm = nitroConfig.wasm || {};
|
|
362
|
+
nitroConfig.wasm.esmImport = false;
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function isVue(id, opts = {}) {
|
|
368
|
+
const { search } = ufo.parseURL(decodeURIComponent(node_url.pathToFileURL(id).href));
|
|
369
|
+
if (id.endsWith(".vue") && !search) {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
if (!search) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
const query = ufo.parseQuery(search);
|
|
376
|
+
if (query.nuxt_component) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
if (query.macro && (search === "?macro=true" || !opts.type || opts.type.includes("script"))) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
const type = "setup" in query ? "script" : query.type;
|
|
383
|
+
if (!("vue" in query) || opts.type && !opts.type.includes(type)) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
const JS_RE = /\.(?:[cm]?j|t)sx?$/;
|
|
389
|
+
function isJS(id) {
|
|
390
|
+
const { pathname } = ufo.parseURL(decodeURIComponent(node_url.pathToFileURL(id).href));
|
|
391
|
+
return JS_RE.test(pathname);
|
|
392
|
+
}
|
|
393
|
+
const TreeShakeComposablesPlugin = unplugin.createUnplugin(() => {
|
|
394
|
+
const composableNames = [
|
|
395
|
+
"defineOgImage",
|
|
396
|
+
"defineOgImageComponent",
|
|
397
|
+
"defineOgImageScreenshot"
|
|
398
|
+
];
|
|
399
|
+
const regexp = `(^\\s*)(${composableNames.join("|")})(?=\\((?!\\) \\{))`;
|
|
400
|
+
const COMPOSABLE_RE = new RegExp(regexp, "m");
|
|
401
|
+
const COMPOSABLE_RE_GLOBAL = new RegExp(regexp, "gm");
|
|
402
|
+
return {
|
|
403
|
+
name: "nuxt-og-image:zero-runtime:transform",
|
|
404
|
+
enforce: "pre",
|
|
405
|
+
transformInclude(id) {
|
|
406
|
+
return isVue(id, { type: ["script"] }) || isJS(id);
|
|
407
|
+
},
|
|
408
|
+
transform(code, id) {
|
|
409
|
+
const s = new MagicString__default(code);
|
|
410
|
+
if (id.endsWith("components.islands.mjs")) ; else {
|
|
411
|
+
const strippedCode = stripLiteral.stripLiteral(code);
|
|
412
|
+
if (!COMPOSABLE_RE.test(code)) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
for (const match of strippedCode.matchAll(COMPOSABLE_RE_GLOBAL)) {
|
|
416
|
+
s.overwrite(match.index, match.index + match[0].length, `${match[1]} import.meta.prerender && ${match[2]}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (s.hasChanged()) {
|
|
420
|
+
return {
|
|
421
|
+
code: s.toString(),
|
|
422
|
+
map: s.generateMap({ hires: true })
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
async function getNuxtModuleOptions(module, nuxt = kit.useNuxt()) {
|
|
430
|
+
const moduleMeta = (typeof module === "string" ? { name: module } : await module.getMeta?.()) || {};
|
|
431
|
+
const { nuxtModule } = await kit.loadNuxtModuleInstance(module, nuxt);
|
|
432
|
+
let moduleEntry;
|
|
433
|
+
for (const m of nuxt.options.modules) {
|
|
434
|
+
if (Array.isArray(m) && m.length >= 2) {
|
|
435
|
+
const _module = m[0];
|
|
436
|
+
const _moduleEntryName = typeof _module === "string" ? _module : (await _module.getMeta?.())?.name || "";
|
|
437
|
+
if (_moduleEntryName === moduleMeta.name)
|
|
438
|
+
moduleEntry = m;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
let inlineOptions = {};
|
|
442
|
+
if (moduleEntry)
|
|
443
|
+
inlineOptions = moduleEntry[1];
|
|
444
|
+
if (nuxtModule.getOptions)
|
|
445
|
+
return nuxtModule.getOptions(inlineOptions, nuxt);
|
|
446
|
+
return inlineOptions;
|
|
447
|
+
}
|
|
448
|
+
function extendTypes(module, template) {
|
|
449
|
+
const nuxt = kit.useNuxt();
|
|
450
|
+
const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
|
|
451
|
+
kit.addTemplate({
|
|
452
|
+
filename: `module/${module}.d.ts`,
|
|
453
|
+
getContents: async () => {
|
|
454
|
+
const typesPath = pathe.relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), resolve("runtime/types"));
|
|
455
|
+
const s = await template({ typesPath });
|
|
456
|
+
return `// Generated by ${module}
|
|
457
|
+
${s}
|
|
458
|
+
export {}
|
|
459
|
+
`;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
nuxt.hooks.hook("prepare:types", ({ references }) => {
|
|
463
|
+
references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) });
|
|
464
|
+
});
|
|
465
|
+
nuxt.hooks.hook("nitro:config", (config) => {
|
|
466
|
+
config.typescript = config.typescript || {};
|
|
467
|
+
config.typescript.tsConfig = config.typescript.tsConfig || {};
|
|
468
|
+
config.typescript.tsConfig.include = config.typescript.tsConfig.include || [];
|
|
469
|
+
config.typescript.tsConfig.include.push(`./module/${module}.d.ts`);
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
function isNuxtGenerate(nuxt = kit.useNuxt()) {
|
|
473
|
+
return nuxt.options._generate || nuxt.options.nitro.static || nuxt.options.nitro.preset === "static";
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function normaliseFontInput(fonts) {
|
|
477
|
+
return fonts.map((f) => {
|
|
478
|
+
if (typeof f === "string") {
|
|
479
|
+
const vals = f.split(":");
|
|
480
|
+
const includesStyle = vals.length === 3;
|
|
481
|
+
let name, weight, style;
|
|
482
|
+
if (includesStyle) {
|
|
483
|
+
name = vals[0];
|
|
484
|
+
style = vals[1];
|
|
485
|
+
weight = vals[2];
|
|
486
|
+
} else {
|
|
487
|
+
name = vals[0];
|
|
488
|
+
weight = vals[1];
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
cacheKey: f,
|
|
492
|
+
name,
|
|
493
|
+
weight: weight || 400,
|
|
494
|
+
style: style || "normal",
|
|
495
|
+
path: void 0
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
cacheKey: f.key || `${f.name}:${f.style}:${f.weight}`,
|
|
500
|
+
style: "normal",
|
|
501
|
+
weight: 400,
|
|
502
|
+
...f
|
|
503
|
+
};
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const isUndefinedOrTruthy = (v) => typeof v === "undefined" || v !== false;
|
|
508
|
+
function checkLocalChrome() {
|
|
509
|
+
if (stdEnv.isCI)
|
|
510
|
+
return false;
|
|
511
|
+
let hasChromeLocally = false;
|
|
512
|
+
try {
|
|
513
|
+
hasChromeLocally = !!chromeLauncher.Launcher.getFirstInstallation();
|
|
514
|
+
} catch {
|
|
515
|
+
}
|
|
516
|
+
return hasChromeLocally;
|
|
517
|
+
}
|
|
518
|
+
async function checkPlaywrightDependency() {
|
|
519
|
+
return !!await kit.tryResolveModule("playwright");
|
|
520
|
+
}
|
|
521
|
+
async function downloadFont(font, storage, mirror) {
|
|
522
|
+
const { name, weight, style } = font;
|
|
523
|
+
const key = `${name}-${style}-${weight}.ttf.base64`;
|
|
524
|
+
if (await storage.hasItem(key))
|
|
525
|
+
return true;
|
|
526
|
+
const host = typeof mirror === "undefined" ? "fonts.googleapis.com" : mirror === true ? "fonts.font.im" : mirror;
|
|
527
|
+
const css = await ofetch.$fetch(`https://${host}/css2?family=${name}:${style === "ital" ? `ital,wght@1,${weight}` : `wght@${weight}`}`, {
|
|
528
|
+
timeout: 10 * 1e3,
|
|
529
|
+
// 10 second timeout
|
|
530
|
+
headers: {
|
|
531
|
+
// Make sure it returns TTF.
|
|
532
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
|
|
533
|
+
}
|
|
534
|
+
}).catch(() => {
|
|
535
|
+
return false;
|
|
536
|
+
});
|
|
537
|
+
if (!css)
|
|
538
|
+
return false;
|
|
539
|
+
const ttfResource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
|
|
540
|
+
if (ttfResource?.[1]) {
|
|
541
|
+
const buf = await ofetch.$fetch(ttfResource[1], { baseURL: host, responseType: "arrayBuffer" });
|
|
542
|
+
const base64Font = Buffer.from(buf).toString("base64");
|
|
543
|
+
await storage.setItem(key, base64Font);
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const module$1 = kit.defineNuxtModule({
|
|
550
|
+
meta: {
|
|
551
|
+
name: "nuxt-og-image",
|
|
552
|
+
compatibility: {
|
|
553
|
+
nuxt: ">=3.10.3",
|
|
554
|
+
bridge: false
|
|
555
|
+
},
|
|
556
|
+
configKey: "ogImage"
|
|
557
|
+
},
|
|
558
|
+
defaults() {
|
|
559
|
+
return {
|
|
560
|
+
enabled: true,
|
|
561
|
+
defaults: {
|
|
562
|
+
emojis: "noto",
|
|
563
|
+
renderer: "satori",
|
|
564
|
+
component: "NuxtSeo",
|
|
565
|
+
extension: "png",
|
|
566
|
+
width: 1200,
|
|
567
|
+
height: 600,
|
|
568
|
+
// default is to cache the image for 3 day (72 hours)
|
|
569
|
+
cacheMaxAgeSeconds: 60 * 60 * 24 * 3
|
|
570
|
+
},
|
|
571
|
+
componentDirs: ["OgImage", "OgImageTemplate"],
|
|
572
|
+
fonts: [],
|
|
573
|
+
runtimeCacheStorage: true,
|
|
574
|
+
debug: stdEnv.isDevelopment
|
|
575
|
+
};
|
|
576
|
+
},
|
|
577
|
+
async setup(config, nuxt) {
|
|
578
|
+
const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
|
|
579
|
+
const { version } = await pkgTypes.readPackageJSON(resolve("../package.json"));
|
|
580
|
+
logger_js.logger.level = config.debug || nuxt.options.debug ? 4 : 3;
|
|
581
|
+
if (config.enabled === false) {
|
|
582
|
+
logger_js.logger.debug("The module is disabled, skipping setup.");
|
|
583
|
+
["defineOgImage", "defineOgImageComponent", "defineOgImageScreenshot"].forEach((name) => {
|
|
584
|
+
kit.addImports({ name, from: resolve(`./runtime/app/composables/mock`) });
|
|
585
|
+
});
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
if (config.enabled && !nuxt.options.ssr) {
|
|
589
|
+
logger_js.logger.warn("Nuxt OG Image is enabled but SSR is disabled.\n\nYou should enable SSR (`ssr: true`) or disable the module (`ogImage: { enabled: false }`).");
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
nuxt.options.alias["#og-image"] = resolve("./runtime");
|
|
593
|
+
nuxt.options.alias["#og-image-cache"] = resolve("./runtime/server/og-image/cache/lru");
|
|
594
|
+
nuxt.options.alias["#nuxt-og-image-utils"] = resolve("./runtime/shared");
|
|
595
|
+
const preset = resolveNitroPreset(nuxt.options.nitro);
|
|
596
|
+
const targetCompatibility = getPresetNitroPresetCompatibility(preset);
|
|
597
|
+
if (config.zeroRuntime) {
|
|
598
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
599
|
+
runtime: {
|
|
600
|
+
chromium: false,
|
|
601
|
+
// should already be false
|
|
602
|
+
satori: false
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
if (!nuxt.options.dev) {
|
|
606
|
+
kit.addBuildPlugin(TreeShakeComposablesPlugin, { server: true, client: true, build: true });
|
|
607
|
+
nuxt.options.alias["#og-image-cache"] = resolve("./runtime/server/og-image/cache/mock");
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
let isUsingSharp = false;
|
|
611
|
+
const userConfiguredExtension = config.defaults.extension;
|
|
612
|
+
const hasConfiguredJpegs = userConfiguredExtension && ["jpeg", "jpg"].includes(userConfiguredExtension);
|
|
613
|
+
if (!!config.sharpOptions || hasConfiguredJpegs && config.defaults.renderer !== "chromium") {
|
|
614
|
+
isUsingSharp = true;
|
|
615
|
+
const hasSharpDependency = !!await kit.tryResolveModule("sharp");
|
|
616
|
+
if (hasSharpDependency && !targetCompatibility.sharp) {
|
|
617
|
+
logger_js.logger.warn(`Rendering JPEGs requires sharp which does not work with ${preset}. Images will be rendered as PNG at runtime.`);
|
|
618
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
619
|
+
runtime: { sharp: false }
|
|
620
|
+
});
|
|
621
|
+
} else if (!hasSharpDependency) {
|
|
622
|
+
logger_js.logger.warn("You have enabled `JPEG` images. These require the `sharp` dependency which is missing, installing it for you.");
|
|
623
|
+
await ensureDependencies(["sharp"]);
|
|
624
|
+
logger_js.logger.warn("Support for `sharp` is limited so check the compatibility guide.");
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (!isUsingSharp) {
|
|
628
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
629
|
+
runtime: { sharp: false },
|
|
630
|
+
dev: { sharp: false },
|
|
631
|
+
prerender: { sharp: false }
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
const hasChromeLocally = checkLocalChrome();
|
|
635
|
+
const hasPlaywrightDependency = await checkPlaywrightDependency();
|
|
636
|
+
const chromeCompatibilityFlags = {
|
|
637
|
+
prerender: config.compatibility?.prerender?.chromium,
|
|
638
|
+
dev: config.compatibility?.dev?.chromium,
|
|
639
|
+
runtime: config.compatibility?.runtime?.chromium
|
|
640
|
+
};
|
|
641
|
+
const chromiumBinding = {
|
|
642
|
+
dev: null,
|
|
643
|
+
prerender: null,
|
|
644
|
+
runtime: null
|
|
645
|
+
};
|
|
646
|
+
if (nuxt.options.dev) {
|
|
647
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.dev))
|
|
648
|
+
chromiumBinding.dev = hasChromeLocally ? "chrome-launcher" : hasPlaywrightDependency ? "playwright" : "on-demand";
|
|
649
|
+
} else {
|
|
650
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.prerender))
|
|
651
|
+
chromiumBinding.prerender = hasChromeLocally ? "chrome-launcher" : hasPlaywrightDependency ? "playwright" : "on-demand";
|
|
652
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.runtime))
|
|
653
|
+
chromiumBinding.runtime = hasPlaywrightDependency ? "playwright" : null;
|
|
654
|
+
}
|
|
655
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
656
|
+
runtime: { chromium: chromiumBinding.runtime },
|
|
657
|
+
dev: { chromium: chromiumBinding.dev },
|
|
658
|
+
prerender: { chromium: chromiumBinding.prerender }
|
|
659
|
+
});
|
|
660
|
+
await import('@resvg/resvg-js').catch(() => {
|
|
661
|
+
logger_js.logger.warn("ReSVG is missing dependencies for environment. Falling back to WASM version, this may slow down PNG rendering.");
|
|
662
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
663
|
+
dev: { resvg: "wasm-fs" },
|
|
664
|
+
prerender: { resvg: "wasm-fs" }
|
|
665
|
+
});
|
|
666
|
+
if (targetCompatibility.resvg === "node") {
|
|
667
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
668
|
+
runtime: { resvg: "wasm" }
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
await kit$1.installNuxtSiteConfig();
|
|
673
|
+
const usingNuxtContent = kit.hasNuxtModule("@nuxt/content");
|
|
674
|
+
const isNuxtContentV3 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^3");
|
|
675
|
+
const isNuxtContentV2 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^2");
|
|
676
|
+
if (isNuxtContentV3) {
|
|
677
|
+
if (typeof config.strictNuxtContentPaths !== "undefined") {
|
|
678
|
+
logger_js.logger.warn("The `strictNuxtContentPaths` option is deprecated and has no effect in Nuxt Content v3.");
|
|
679
|
+
}
|
|
680
|
+
} else if (isNuxtContentV2) {
|
|
681
|
+
kit.addServerPlugin(resolve("./runtime/server/plugins/nuxt-content"));
|
|
682
|
+
}
|
|
683
|
+
if (!config.fonts.length) {
|
|
684
|
+
config.fonts = [
|
|
685
|
+
{ name: "Inter", weight: 400, path: resolve("./runtime/assets/Inter-normal-400.ttf.base64"), absolutePath: true },
|
|
686
|
+
{ name: "Inter", weight: 700, path: resolve("./runtime/assets/Inter-normal-700.ttf.base64"), absolutePath: true }
|
|
687
|
+
];
|
|
688
|
+
}
|
|
689
|
+
let publicDirAbs = nuxt.options.dir.public;
|
|
690
|
+
if (!pathe.isAbsolute(publicDirAbs)) {
|
|
691
|
+
publicDirAbs = publicDirAbs in nuxt.options.alias ? nuxt.options.alias[publicDirAbs] : resolve(nuxt.options.rootDir, publicDirAbs);
|
|
692
|
+
}
|
|
693
|
+
const serverFontsDir = resolve(nuxt.options.buildDir, "cache", `nuxt-og-image@${version}`, "_fonts");
|
|
694
|
+
const fontStorage = unstorage.createStorage({
|
|
695
|
+
driver: fsDriver__default({
|
|
696
|
+
base: serverFontsDir
|
|
697
|
+
})
|
|
698
|
+
});
|
|
699
|
+
config.fonts = (await Promise.all(normaliseFontInput(config.fonts).map(async (f) => {
|
|
700
|
+
const fontKey = `${f.name}:${f.style}:${f.weight}`;
|
|
701
|
+
const fontFileBase = fontKey.replaceAll(":", "-");
|
|
702
|
+
if (!f.key && !f.path) {
|
|
703
|
+
if (preset === "stackblitz") {
|
|
704
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because remote fonts are not available in StackBlitz, please use a local font.`);
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
if (await downloadFont(f, fontStorage, config.googleFontMirror)) {
|
|
708
|
+
f.key = `nuxt-og-image:fonts:${fontFileBase}.ttf.base64`;
|
|
709
|
+
} else {
|
|
710
|
+
logger_js.logger.warn(`Failed to download font ${fontKey}. You may be offline or behind a firewall blocking Google. Consider setting \`googleFontMirror: true\`.`);
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
} else if (f.path) {
|
|
714
|
+
const extension = pathe.basename(f.path.replace(".base64", "")).split(".").pop();
|
|
715
|
+
if (!["woff", "ttf", "otf"].includes(extension)) {
|
|
716
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because the file extension ${extension} is not supported. Only woff, ttf and otf are supported.`);
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
if (!f.absolutePath)
|
|
720
|
+
f.path = resolve(publicDirAbs, ufo.withoutLeadingSlash(f.path));
|
|
721
|
+
if (!fs.existsSync(f.path)) {
|
|
722
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because the file does not exist at path ${f.path}.`);
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
725
|
+
const fontData = await promises.readFile(f.path, f.path.endsWith(".base64") ? "utf-8" : "base64");
|
|
726
|
+
f.key = `nuxt-og-image:fonts:${fontFileBase}.${extension}.base64`;
|
|
727
|
+
await fontStorage.setItem(`${fontFileBase}.${extension}.base64`, fontData);
|
|
728
|
+
delete f.path;
|
|
729
|
+
delete f.absolutePath;
|
|
730
|
+
}
|
|
731
|
+
return f;
|
|
732
|
+
}))).filter(Boolean);
|
|
733
|
+
const fontKeys = config.fonts.map((f) => f.key?.split(":").pop());
|
|
734
|
+
const fontStorageKeys = await fontStorage.getKeys();
|
|
735
|
+
await Promise.all(fontStorageKeys.filter((key) => !fontKeys.includes(key)).map(async (key) => {
|
|
736
|
+
logger_js.logger.info(`Nuxt OG Image removing outdated cached font file \`${key}\``);
|
|
737
|
+
await fontStorage.removeItem(key);
|
|
738
|
+
}));
|
|
739
|
+
if (!config.zeroRuntime) {
|
|
740
|
+
nuxt.options.nitro.serverAssets = nuxt.options.nitro.serverAssets || [];
|
|
741
|
+
nuxt.options.nitro.serverAssets.push({ baseName: "nuxt-og-image:fonts", dir: serverFontsDir });
|
|
742
|
+
}
|
|
743
|
+
nuxt.options.experimental.componentIslands ||= true;
|
|
744
|
+
const basePath = config.zeroRuntime ? "./runtime/server/routes/__zero-runtime" : "./runtime/server/routes";
|
|
745
|
+
kit.addServerHandler({
|
|
746
|
+
lazy: true,
|
|
747
|
+
route: "/__og-image__/font/**",
|
|
748
|
+
handler: resolve(`${basePath}/font`)
|
|
749
|
+
});
|
|
750
|
+
if (config.debug || nuxt.options.dev) {
|
|
751
|
+
kit.addServerHandler({
|
|
752
|
+
lazy: true,
|
|
753
|
+
route: "/__og-image__/debug.json",
|
|
754
|
+
handler: resolve("./runtime/server/routes/debug.json")
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
kit.addServerHandler({
|
|
758
|
+
lazy: true,
|
|
759
|
+
route: "/__og-image__/image/**",
|
|
760
|
+
handler: resolve(`${basePath}/image`)
|
|
761
|
+
});
|
|
762
|
+
kit.addServerHandler({
|
|
763
|
+
lazy: true,
|
|
764
|
+
route: "/__og-image__/static/**",
|
|
765
|
+
handler: resolve(`${basePath}/image`)
|
|
766
|
+
});
|
|
767
|
+
if (!nuxt.options.dev) {
|
|
768
|
+
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] = [];
|
|
769
|
+
}
|
|
770
|
+
["defineOgImage", "defineOgImageComponent", "defineOgImageScreenshot"].forEach((name) => {
|
|
771
|
+
kit.addImports({
|
|
772
|
+
name,
|
|
773
|
+
from: resolve(`./runtime/app/composables/${name}`)
|
|
774
|
+
});
|
|
775
|
+
if (!nuxt.options.dev) {
|
|
776
|
+
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"].push(name);
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
if (!config.zeroRuntime || nuxt.options.dev) {
|
|
780
|
+
await kit.addComponentsDir({
|
|
781
|
+
path: resolve("./runtime/app/components/Templates/Community"),
|
|
782
|
+
island: true
|
|
783
|
+
// watch: true,
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
[
|
|
787
|
+
// new
|
|
788
|
+
"OgImage",
|
|
789
|
+
"OgImageScreenshot"
|
|
790
|
+
].forEach((name) => {
|
|
791
|
+
kit.addComponent({
|
|
792
|
+
name,
|
|
793
|
+
filePath: resolve(`./runtime/app/components/OgImage/${name}`),
|
|
794
|
+
...config.componentOptions
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
const basePluginPath = `./runtime/app/plugins${config.zeroRuntime ? "/__zero-runtime" : ""}`;
|
|
798
|
+
kit.addPlugin({ mode: "server", src: resolve(`${basePluginPath}/route-rule-og-image.server`) });
|
|
799
|
+
kit.addPlugin({ mode: "server", src: resolve(`${basePluginPath}/og-image-canonical-urls.server`) });
|
|
800
|
+
const ogImageComponentCtx = { components: [] };
|
|
801
|
+
nuxt.hook("components:extend", (components) => {
|
|
802
|
+
ogImageComponentCtx.components = [];
|
|
803
|
+
components.forEach((component) => {
|
|
804
|
+
let valid = false;
|
|
805
|
+
config.componentDirs.forEach((dir) => {
|
|
806
|
+
if (component.pascalName.startsWith(dir) || component.kebabName.startsWith(dir) || component.shortPath.includes(`/${dir}/`)) {
|
|
807
|
+
valid = true;
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
if (component.filePath.includes(resolve("./runtime/app/components/Templates")))
|
|
811
|
+
valid = true;
|
|
812
|
+
if (valid && fs__namespace.existsSync(component.filePath)) {
|
|
813
|
+
component.island = true;
|
|
814
|
+
component.mode = "server";
|
|
815
|
+
let category = "app";
|
|
816
|
+
if (component.filePath.includes(resolve("./runtime/app/components/Templates/Community")))
|
|
817
|
+
category = "community";
|
|
818
|
+
const componentFile = fs__namespace.readFileSync(component.filePath, "utf-8");
|
|
819
|
+
const credits = componentFile.split("\n").find((line) => line.startsWith(" * @credits"))?.replace("* @credits", "").trim();
|
|
820
|
+
ogImageComponentCtx.components.push({
|
|
821
|
+
// purge cache when component changes
|
|
822
|
+
hash: ohash.hash(componentFile),
|
|
823
|
+
pascalName: component.pascalName,
|
|
824
|
+
kebabName: component.kebabName,
|
|
825
|
+
path: nuxt.options.dev ? component.filePath : void 0,
|
|
826
|
+
category,
|
|
827
|
+
credits
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
nuxt.hooks.hook("nuxt-og-image:components", ogImageComponentCtx);
|
|
832
|
+
});
|
|
833
|
+
kit.addTemplate({
|
|
834
|
+
filename: "nuxt-og-image/components.mjs",
|
|
835
|
+
getContents() {
|
|
836
|
+
return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}`;
|
|
837
|
+
},
|
|
838
|
+
options: { mode: "server" }
|
|
839
|
+
});
|
|
840
|
+
nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {};
|
|
841
|
+
nuxt.options.nitro.virtual["#og-image-virtual/component-names.mjs"] = () => {
|
|
842
|
+
return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}`;
|
|
843
|
+
};
|
|
844
|
+
let unoCssConfig = {};
|
|
845
|
+
nuxt.hook("tailwindcss:config", (tailwindConfig) => {
|
|
846
|
+
unoCssConfig = defu.defu(tailwindConfig.theme?.extend, { ...tailwindConfig.theme, extend: void 0 });
|
|
847
|
+
});
|
|
848
|
+
nuxt.hook("unocss:config", (_unoCssConfig) => {
|
|
849
|
+
unoCssConfig = { ..._unoCssConfig.theme };
|
|
850
|
+
});
|
|
851
|
+
nuxt.options.nitro.virtual["#og-image-virtual/unocss-config.mjs"] = () => {
|
|
852
|
+
return `export const theme = ${JSON.stringify(unoCssConfig)}`;
|
|
853
|
+
};
|
|
854
|
+
extendTypes("nuxt-og-image", ({ typesPath }) => {
|
|
855
|
+
const componentImports = ogImageComponentCtx.components.map((component) => {
|
|
856
|
+
const relativeComponentPath = pathe.relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), component.path);
|
|
857
|
+
const name = config.componentDirs.sort((a, b) => b.length - a.length).reduce((name2, dir) => {
|
|
858
|
+
return name2.replace(new RegExp(`^${dir}`), "");
|
|
859
|
+
}, component.pascalName);
|
|
860
|
+
return ` '${name}': typeof import('${relativeComponentPath}')['default']`;
|
|
861
|
+
}).join("\n");
|
|
862
|
+
return `
|
|
863
|
+
declare module 'nitropack' {
|
|
864
|
+
interface NitroRouteRules {
|
|
865
|
+
ogImage?: false | import('${typesPath}').OgImageOptions & Record<string, any>
|
|
866
|
+
}
|
|
867
|
+
interface NitroRouteConfig {
|
|
868
|
+
ogImage?: false | import('${typesPath}').OgImageOptions & Record<string, any>
|
|
869
|
+
}
|
|
870
|
+
interface NitroRuntimeHooks {
|
|
871
|
+
'nuxt-og-image:context': (ctx: import('${typesPath}').OgImageRenderEventContext) => void | Promise<void>
|
|
872
|
+
'nuxt-og-image:satori:vnodes': (vnodes: import('${typesPath}').VNode, ctx: import('${typesPath}').OgImageRenderEventContext) => void | Promise<void>
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
declare module '#og-image/components' {
|
|
877
|
+
export interface OgImageComponents {
|
|
878
|
+
${componentImports}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
declare module '#og-image/unocss-config' {
|
|
882
|
+
export type theme = any
|
|
883
|
+
}
|
|
884
|
+
`;
|
|
885
|
+
});
|
|
886
|
+
const cacheEnabled = typeof config.runtimeCacheStorage !== "undefined" && config.runtimeCacheStorage !== false;
|
|
887
|
+
const runtimeCacheStorage = typeof config.runtimeCacheStorage === "boolean" ? "default" : config.runtimeCacheStorage.driver;
|
|
888
|
+
let baseCacheKey = runtimeCacheStorage === "default" ? `/cache/nuxt-og-image/${version}` : `/nuxt-og-image/${version}`;
|
|
889
|
+
if (!cacheEnabled)
|
|
890
|
+
baseCacheKey = false;
|
|
891
|
+
if (!nuxt.options.dev && config.runtimeCacheStorage && typeof config.runtimeCacheStorage === "object") {
|
|
892
|
+
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
893
|
+
nuxt.options.nitro.storage["nuxt-og-image"] = config.runtimeCacheStorage;
|
|
894
|
+
}
|
|
895
|
+
nuxt.hooks.hook("modules:done", async () => {
|
|
896
|
+
const normalisedFonts = normaliseFontInput(config.fonts);
|
|
897
|
+
if (!isNuxtGenerate() && nuxt.options.build) {
|
|
898
|
+
nuxt.options.nitro = nuxt.options.nitro || {};
|
|
899
|
+
nuxt.options.nitro.prerender = nuxt.options.nitro.prerender || {};
|
|
900
|
+
nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes || [];
|
|
901
|
+
}
|
|
902
|
+
const hasColorModeModule = kit.hasNuxtModule("@nuxtjs/color-mode");
|
|
903
|
+
const colorModeOptions = hasColorModeModule ? await getNuxtModuleOptions("@nuxtjs/color-mode") : {};
|
|
904
|
+
let colorPreference = colorModeOptions.preference;
|
|
905
|
+
if (!colorPreference || colorPreference === "system")
|
|
906
|
+
colorPreference = colorModeOptions.fallback;
|
|
907
|
+
if (!colorPreference || colorPreference === "system")
|
|
908
|
+
colorPreference = "light";
|
|
909
|
+
const runtimeConfig = {
|
|
910
|
+
version,
|
|
911
|
+
// binding options
|
|
912
|
+
satoriOptions: config.satoriOptions || {},
|
|
913
|
+
resvgOptions: config.resvgOptions || {},
|
|
914
|
+
sharpOptions: config.sharpOptions === true ? {} : config.sharpOptions || {},
|
|
915
|
+
publicStoragePath: `root${publicDirAbs.replace(nuxt.options.rootDir, "").replaceAll("/", ":")}`,
|
|
916
|
+
defaults: config.defaults,
|
|
917
|
+
debug: config.debug,
|
|
918
|
+
// avoid adding credentials
|
|
919
|
+
baseCacheKey,
|
|
920
|
+
// convert the fonts to uniform type to fix ts issue
|
|
921
|
+
fonts: normalisedFonts,
|
|
922
|
+
hasNuxtIcon: kit.hasNuxtModule("nuxt-icon") || kit.hasNuxtModule("@nuxt/icon"),
|
|
923
|
+
colorPreference,
|
|
924
|
+
strictNuxtContentPaths: config.strictNuxtContentPaths,
|
|
925
|
+
// @ts-expect-error runtime type
|
|
926
|
+
isNuxtContentDocumentDriven: config.strictNuxtContentPaths || !!nuxt.options.content?.documentDriven
|
|
927
|
+
};
|
|
928
|
+
nuxt.hooks.callHook("nuxt-og-image:runtime-config", runtimeConfig);
|
|
929
|
+
nuxt.options.runtimeConfig["nuxt-og-image"] = runtimeConfig;
|
|
930
|
+
});
|
|
931
|
+
if (nuxt.options.dev) {
|
|
932
|
+
setupDevHandler(config, resolve);
|
|
933
|
+
setupDevToolsUI(config, resolve);
|
|
934
|
+
} else if (isNuxtGenerate()) {
|
|
935
|
+
setupGenerateHandler(config, resolve);
|
|
936
|
+
} else if (nuxt.options.build) {
|
|
937
|
+
await setupBuildHandler(config, resolve);
|
|
938
|
+
}
|
|
939
|
+
if (nuxt.options.build)
|
|
940
|
+
kit.addServerPlugin(resolve("./runtime/server/plugins/prerender"));
|
|
941
|
+
setupPrerenderHandler(config, resolve);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
module.exports = module$1;
|