nuxt-og-image 2.0.0-beta.12 → 2.0.0-beta.14
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/dist/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/composables/defineOgImage.mjs +1 -3
- package/dist/runtime/nitro/plugins/prerender.d.ts +2 -0
- package/dist/runtime/nitro/plugins/prerender.mjs +19 -0
- package/dist/runtime/nitro/providers/svg2png/universal.mjs +2 -1
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { defineNuxtModule, createResolver, addTemplate, addServerHandler, addImports, addComponent } from '@nuxt/kit';
|
|
2
|
+
import { defineNuxtModule, createResolver, addTemplate, addServerHandler, addImports, addComponent, addServerPlugin } from '@nuxt/kit';
|
|
3
3
|
import { execa } from 'execa';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import defu from 'defu';
|
|
@@ -330,6 +330,7 @@ export {}
|
|
|
330
330
|
});
|
|
331
331
|
const runtimeDir = resolve("./runtime");
|
|
332
332
|
nuxt.options.build.transpile.push(runtimeDir);
|
|
333
|
+
addServerPlugin(resolve("./runtime/nitro/plugins/prerender"));
|
|
333
334
|
const moduleAssetDir = resolve("./runtime/public-assets");
|
|
334
335
|
const assetDirs = [
|
|
335
336
|
resolve(nuxt.options.rootDir, nuxt.options.dir.public),
|
|
@@ -32,12 +32,10 @@ export function defineOgImageStatic(options = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
export function defineOgImage(options = {}) {
|
|
34
34
|
if (process.server) {
|
|
35
|
-
const {
|
|
35
|
+
const { defaults, siteUrl } = useRuntimeConfig()["nuxt-og-image"];
|
|
36
36
|
const router = useRouter();
|
|
37
37
|
const route = router?.currentRoute?.value?.path || "";
|
|
38
38
|
const e = useRequestEvent();
|
|
39
|
-
if ((forcePrerender || options.static) && options.provider === "satori")
|
|
40
|
-
e.res.setHeader("x-nitro-prerender", `${route === "/" ? "" : route}/__og_image__/og.png`);
|
|
41
39
|
const baseUrl = process.env.prerender ? siteUrl : useHostname(e);
|
|
42
40
|
const meta = [
|
|
43
41
|
{
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { appendHeader } from "h3";
|
|
2
|
+
import { joinURL } from "ufo";
|
|
3
|
+
import { extractOgImageOptions } from "../utils-pure.mjs";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
6
|
+
if (!process.env.prerender)
|
|
7
|
+
return;
|
|
8
|
+
const { forcePrerender } = useRuntimeConfig()["nuxt-og-image"];
|
|
9
|
+
nitroApp.hooks.hook("render:html", async (ctx, { event }) => {
|
|
10
|
+
const url = event.node.req.url;
|
|
11
|
+
if (url.includes(".") || url.startsWith("/__nuxt_island/"))
|
|
12
|
+
return;
|
|
13
|
+
const options = extractOgImageOptions(ctx.head.join("\n"));
|
|
14
|
+
if (!options)
|
|
15
|
+
return;
|
|
16
|
+
if ((forcePrerender || options.static) && options.provider === "satori")
|
|
17
|
+
appendHeader(event, "x-nitro-prerender", joinURL(url, "/__og_image__/og.png"));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -4,7 +4,8 @@ export default async function(svg, options) {
|
|
|
4
4
|
const loader = wasmLoader("/* NUXT_OG_IMAGE_SVG2PNG_WASM */", "/svg2png.wasm", options.baseUrl);
|
|
5
5
|
if (!await loader.loaded()) {
|
|
6
6
|
await initialize(await loader.load()).catch((e) => {
|
|
7
|
-
|
|
7
|
+
if (!e.message.trim().endsWith("function can be used only once."))
|
|
8
|
+
throw e;
|
|
8
9
|
});
|
|
9
10
|
}
|
|
10
11
|
return await svg2png(svg, options);
|