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
|
@@ -2,8 +2,9 @@ import { defu } from "defu";
|
|
|
2
2
|
import { parseURL, withoutBase } from "ufo";
|
|
3
3
|
import { createRouter as createRadixRouter, toRouteMatcher } from "radix3";
|
|
4
4
|
import { normaliseOptions } from "../../core/options/normalise.mjs";
|
|
5
|
-
import { getOgImagePath, isInternalRoute } from "../../
|
|
6
|
-
import {
|
|
5
|
+
import { getOgImagePath, isInternalRoute, useOgImageRuntimeConfig } from "../../utils.mjs";
|
|
6
|
+
import { createOgImageMeta } from "../utils.mjs";
|
|
7
|
+
import { defineNuxtPlugin, useRequestEvent } from "#imports";
|
|
7
8
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
8
9
|
nuxtApp.hooks.hook("app:rendered", async (ctx) => {
|
|
9
10
|
const { ssrContext } = ctx;
|
|
@@ -14,59 +15,24 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
14
15
|
const _routeRulesMatcher = toRouteMatcher(
|
|
15
16
|
createRadixRouter({ routes: ssrContext?.runtimeConfig?.nitro?.routeRules })
|
|
16
17
|
);
|
|
17
|
-
|
|
18
|
+
let routeRules = defu({}, ..._routeRulesMatcher.matchAll(
|
|
18
19
|
withoutBase(path.split("?")[0], ssrContext?.runtimeConfig?.app.baseURL)
|
|
19
20
|
).reverse()).ogImage;
|
|
20
21
|
if (typeof routeRules === "undefined")
|
|
21
22
|
return;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const ogImageInstances = nuxtApp.ssrContext._ogImageInstances || [];
|
|
24
|
+
if (routeRules === false) {
|
|
25
|
+
ogImageInstances?.forEach((e2) => {
|
|
26
|
+
e2.dispose();
|
|
27
|
+
});
|
|
28
|
+
nuxtApp.ssrContext._ogImagePayload = void 0;
|
|
29
|
+
nuxtApp.ssrContext._ogImageInstances = void 0;
|
|
27
30
|
return;
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const src = getOgImagePath(ssrContext.url, optionsWithDefault.extension);
|
|
35
|
-
ssrContext?.head.push({
|
|
36
|
-
script: [
|
|
37
|
-
{
|
|
38
|
-
id: "nuxt-og-image-options",
|
|
39
|
-
type: "application/json",
|
|
40
|
-
processTemplateParams: true,
|
|
41
|
-
innerHTML: () => {
|
|
42
|
-
const payload = {
|
|
43
|
-
title: "%s"
|
|
44
|
-
};
|
|
45
|
-
Object.entries(options).forEach(([key, val]) => {
|
|
46
|
-
payload[key.replace(/-([a-z])/g, (g) => g[1].toUpperCase())] = val;
|
|
47
|
-
});
|
|
48
|
-
return payload;
|
|
49
|
-
},
|
|
50
|
-
// we want this to be last in our head
|
|
51
|
-
tagPosition: "bodyClose"
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
meta: [
|
|
55
|
-
{ property: "og:image", content: src },
|
|
56
|
-
{ property: "og:image:width", content: optionsWithDefault.width },
|
|
57
|
-
{ property: "og:image:height", content: optionsWithDefault.height },
|
|
58
|
-
{ property: "og:image:type", content: `image/${optionsWithDefault.extension}` },
|
|
59
|
-
{ property: "og:image:alt", content: optionsWithDefault.alt },
|
|
60
|
-
// twitter
|
|
61
|
-
{ name: "twitter:card", content: "summary_large_image" },
|
|
62
|
-
{ name: "twitter:image:src", content: src },
|
|
63
|
-
{ name: "twitter:image:width", content: optionsWithDefault.width },
|
|
64
|
-
{ name: "twitter:image:height", content: optionsWithDefault.height },
|
|
65
|
-
{ name: "twitter:image:alt", content: optionsWithDefault.alt }
|
|
66
|
-
]
|
|
67
|
-
}, {
|
|
68
|
-
mode: "server",
|
|
69
|
-
tagPriority: 35
|
|
70
|
-
});
|
|
32
|
+
routeRules = defu(nuxtApp.ssrContext?.event.context._nitro?.routeRules?.ogImage, routeRules);
|
|
33
|
+
const { defaults } = useOgImageRuntimeConfig();
|
|
34
|
+
const resolvedOptions = normaliseOptions(defu(routeRules, defaults));
|
|
35
|
+
const src = getOgImagePath(ssrContext.url, resolvedOptions);
|
|
36
|
+
createOgImageMeta(src, routeRules, resolvedOptions, nuxtApp.ssrContext);
|
|
71
37
|
});
|
|
72
38
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defu } from "defu";
|
|
2
|
+
import { separateProps } from "../utils.mjs";
|
|
3
|
+
import { useServerHead } from "#imports";
|
|
4
|
+
export function createOgImageMeta(src, input, resolvedOptions, ssrContext) {
|
|
5
|
+
const _input = separateProps(defu(input, ssrContext._ogImagePayload));
|
|
6
|
+
const url = src || input.url || resolvedOptions.url;
|
|
7
|
+
let urlExtension = (url.split("/").pop() || url).split(".").pop() || resolvedOptions.extension;
|
|
8
|
+
if (urlExtension === "jpg")
|
|
9
|
+
urlExtension = "jpeg";
|
|
10
|
+
const meta = [
|
|
11
|
+
{ property: "og:image", content: url },
|
|
12
|
+
{ property: "og:image:type", content: `image/${urlExtension}` },
|
|
13
|
+
{ name: "twitter:card", content: "summary_large_image" },
|
|
14
|
+
{ name: "twitter:image:src", content: url }
|
|
15
|
+
];
|
|
16
|
+
if (resolvedOptions.width) {
|
|
17
|
+
meta.push({ property: "og:image:width", content: resolvedOptions.width });
|
|
18
|
+
meta.push({ name: "twitter:image:width", content: resolvedOptions.width });
|
|
19
|
+
}
|
|
20
|
+
if (resolvedOptions.height) {
|
|
21
|
+
meta.push({ property: "og:image:height", content: resolvedOptions.height });
|
|
22
|
+
meta.push({ name: "twitter:image:height", content: resolvedOptions.height });
|
|
23
|
+
}
|
|
24
|
+
if (resolvedOptions.alt) {
|
|
25
|
+
meta.push({ property: "og:image:alt", content: resolvedOptions.alt });
|
|
26
|
+
meta.push({ name: "twitter:image:alt", content: resolvedOptions.alt });
|
|
27
|
+
}
|
|
28
|
+
ssrContext._ogImageInstances = ssrContext._ogImageInstances || [];
|
|
29
|
+
const script = [];
|
|
30
|
+
if (src) {
|
|
31
|
+
script.push({
|
|
32
|
+
id: "nuxt-og-image-options",
|
|
33
|
+
type: "application/json",
|
|
34
|
+
processTemplateParams: true,
|
|
35
|
+
innerHTML: () => {
|
|
36
|
+
if (!_input.props.title)
|
|
37
|
+
_input.props.title = "%s";
|
|
38
|
+
delete _input.url;
|
|
39
|
+
return _input;
|
|
40
|
+
},
|
|
41
|
+
// we want this to be last in our head
|
|
42
|
+
tagPosition: "bodyClose"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const instance = useServerHead({
|
|
46
|
+
script,
|
|
47
|
+
meta
|
|
48
|
+
}, {
|
|
49
|
+
tagPriority: 35
|
|
50
|
+
});
|
|
51
|
+
ssrContext._ogImagePayload = _input;
|
|
52
|
+
ssrContext._ogImageInstances.push(instance);
|
|
53
|
+
}
|
|
@@ -4,8 +4,6 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
4
4
|
source: any;
|
|
5
5
|
};
|
|
6
6
|
componentNames: any;
|
|
7
|
-
runtimeConfig:
|
|
8
|
-
baseCacheKey: string;
|
|
9
|
-
cachedKeys: string[];
|
|
7
|
+
runtimeConfig: import("../../../types").OgImageRuntimeConfig;
|
|
10
8
|
}>>;
|
|
11
9
|
export default _default;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { defineEventHandler, setHeader } from "h3";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useOgImageRuntimeConfig } from "../../../utils.mjs";
|
|
3
|
+
import { useSiteConfig } from "#imports";
|
|
4
4
|
import { componentNames } from "#nuxt-og-image/component-names.mjs";
|
|
5
5
|
export default defineEventHandler(async (e) => {
|
|
6
6
|
setHeader(e, "Content-Type", "application/json");
|
|
7
|
-
const runtimeConfig =
|
|
7
|
+
const runtimeConfig = useOgImageRuntimeConfig();
|
|
8
8
|
const siteConfig = await useSiteConfig(e, { debug: true });
|
|
9
|
-
const baseCacheKey = runtimeConfig.runtimeCacheStorage === "default" ? `/cache/nuxt-og-image@${runtimeConfig.version}` : `/nuxt-og-image@${runtimeConfig.version}`;
|
|
10
|
-
const cache = prefixStorage(useStorage(), `${baseCacheKey}/`);
|
|
11
9
|
return {
|
|
12
10
|
siteConfigUrl: {
|
|
13
11
|
value: siteConfig.url,
|
|
14
12
|
source: siteConfig._context.url || "unknown"
|
|
15
13
|
},
|
|
16
14
|
componentNames,
|
|
17
|
-
runtimeConfig
|
|
18
|
-
baseCacheKey,
|
|
19
|
-
cachedKeys: await cache.getKeys()
|
|
15
|
+
runtimeConfig
|
|
20
16
|
};
|
|
21
17
|
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { H3Error, createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
2
|
+
import { resolveRendererContext } from "../../../core/utils/resolveRendererContext.mjs";
|
|
3
|
+
import { fetchIsland } from "../../../core/html/fetchIsland.mjs";
|
|
4
|
+
import { devIframeTemplate } from "../../../core/html/devIframeTemplate.mjs";
|
|
5
|
+
import { applyInlineCss } from "../../../core/html/applyInlineCss.mjs";
|
|
6
|
+
import { useOgImageBufferCache } from "../../../cache.mjs";
|
|
7
|
+
import { useOgImageRuntimeConfig } from "../../../utils.mjs";
|
|
8
|
+
import { useSiteConfig } from "#imports";
|
|
9
|
+
export default defineEventHandler(async (e) => {
|
|
10
|
+
const ctx = await resolveRendererContext(e);
|
|
11
|
+
if (ctx instanceof H3Error)
|
|
12
|
+
return ctx;
|
|
13
|
+
const { isDebugJsonPayload, extension, options, renderer } = ctx;
|
|
14
|
+
const { debug, baseCacheKey } = useOgImageRuntimeConfig();
|
|
15
|
+
const compatibility = [];
|
|
16
|
+
if (isDebugJsonPayload) {
|
|
17
|
+
const queryExtension = getQuery(e).extension || ctx.options.extension;
|
|
18
|
+
if (["jpeg", "jpg"].includes(queryExtension) && options.renderer === "satori")
|
|
19
|
+
compatibility.push("Converting PNGs to JPEGs requires Sharp which only runs on Node based systems.");
|
|
20
|
+
if (options.renderer === "chromium")
|
|
21
|
+
compatibility.push("Using Chromium to generate images is only supported in Node based environments. It's recommended to only use this if you're prerendering");
|
|
22
|
+
if (await applyInlineCss(ctx, await fetchIsland(ctx)))
|
|
23
|
+
compatibility.push("Inlining CSS is only supported in Node based environments.");
|
|
24
|
+
setHeader(e, "Content-Type", "application/json");
|
|
25
|
+
return {
|
|
26
|
+
compatibility,
|
|
27
|
+
...ctx,
|
|
28
|
+
siteConfig: useSiteConfig(e),
|
|
29
|
+
...options.renderer === "satori" ? await renderer.debug(ctx) : void 0
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
switch (extension) {
|
|
33
|
+
case "html":
|
|
34
|
+
setHeader(e, "Content-Type", `text/html`);
|
|
35
|
+
return devIframeTemplate(ctx);
|
|
36
|
+
case "svg":
|
|
37
|
+
if (!debug && !import.meta.dev) {
|
|
38
|
+
return createError({
|
|
39
|
+
statusCode: 404
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (ctx.renderer.name !== "satori") {
|
|
43
|
+
return createError({
|
|
44
|
+
statusCode: 400,
|
|
45
|
+
statusMessage: `Generating ${extension}'s with ${renderer.name} is not supported.`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
setHeader(e, "Content-Type", `image/svg+xml`);
|
|
49
|
+
return (await ctx.renderer.debug(ctx)).svg;
|
|
50
|
+
case "png":
|
|
51
|
+
case "jpeg":
|
|
52
|
+
case "jpg":
|
|
53
|
+
if (!renderer.supportedFormats.includes(extension)) {
|
|
54
|
+
return createError({
|
|
55
|
+
statusCode: 400,
|
|
56
|
+
statusMessage: `Generating ${extension}'s with ${renderer.name} is not supported.`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
setHeader(e, "Content-Type", `image/${extension === "jpg" ? "jpeg" : extension}`);
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
return createError({
|
|
63
|
+
statusCode: 400,
|
|
64
|
+
statusMessage: `Invalid request for og.${extension}.`
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const cacheApi = await useOgImageBufferCache(ctx, {
|
|
68
|
+
cacheMaxAgeSeconds: ctx.options.cacheMaxAgeSeconds,
|
|
69
|
+
baseCacheKey
|
|
70
|
+
});
|
|
71
|
+
if (typeof cacheApi === "undefined")
|
|
72
|
+
return;
|
|
73
|
+
let image = cacheApi.cachedItem;
|
|
74
|
+
if (!image) {
|
|
75
|
+
image = await renderer.createImage(ctx);
|
|
76
|
+
if (image instanceof H3Error)
|
|
77
|
+
return image;
|
|
78
|
+
if (!image) {
|
|
79
|
+
return createError({
|
|
80
|
+
statusCode: 500,
|
|
81
|
+
statusMessage: `Failed to generate og.${extension}.`
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
await cacheApi.update(image);
|
|
85
|
+
}
|
|
86
|
+
return image;
|
|
87
|
+
});
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { Buffer } from 'node:buffer';
|
|
3
1
|
import type { html } from 'satori-html';
|
|
4
2
|
import type { H3Error, H3Event } from 'h3';
|
|
5
3
|
import type { ResvgRenderOptions } from '@resvg/resvg-js';
|
|
6
4
|
import type { SatoriOptions } from 'satori';
|
|
5
|
+
import type { AllowedComponentProps, Component, ComponentCustomProps, VNodeProps } from '@vue/runtime-core';
|
|
6
|
+
import type { SharpOptions } from 'sharp';
|
|
7
|
+
import type { OgImageComponents } from '#nuxt-og-image/components';
|
|
8
|
+
export interface H3EventOgImageRender {
|
|
9
|
+
e: H3Event;
|
|
10
|
+
extension: 'png' | 'jpeg' | 'jpg' | 'svg' | 'html' | 'json';
|
|
11
|
+
key: string;
|
|
12
|
+
basePath: string;
|
|
13
|
+
renderer: Renderer;
|
|
14
|
+
options: OgImageOptions;
|
|
15
|
+
isDebugJsonPayload: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type IconifyEmojiIconSets = 'twemoji' | 'noto' | 'fluent-emoji' | 'fluent-emoji-flat' | 'fluent-emoji-high-contrast' | 'noto-v1' | 'emojione' | 'emojione-monotone' | 'emojione-v1' | 'streamline-emojis' | 'openmoji';
|
|
18
|
+
export interface OgImageRuntimeConfig {
|
|
19
|
+
version: string;
|
|
20
|
+
satoriOptions: SatoriOptions;
|
|
21
|
+
resvgOptions: ResvgRenderOptions;
|
|
22
|
+
sharpOptions: SharpOptions;
|
|
23
|
+
runtimeSatori: boolean;
|
|
24
|
+
runtimeChromium: boolean;
|
|
25
|
+
defaults: OgImageOptions;
|
|
26
|
+
debug: boolean;
|
|
27
|
+
baseCacheKey: string;
|
|
28
|
+
fonts: FontConfig[];
|
|
29
|
+
hasNuxtIcon: boolean;
|
|
30
|
+
colorPreference: 'light' | 'dark';
|
|
31
|
+
}
|
|
7
32
|
export interface OgImageComponent {
|
|
8
33
|
path?: string;
|
|
9
34
|
pascalName: string;
|
|
10
35
|
kebabName: string;
|
|
11
36
|
hash: string;
|
|
12
|
-
category: 'app' | '
|
|
37
|
+
category: 'app' | 'community' | 'pro';
|
|
13
38
|
credits?: string;
|
|
14
39
|
}
|
|
15
40
|
export interface ScreenshotOptions {
|
|
@@ -33,49 +58,74 @@ export interface ScreenshotOptions {
|
|
|
33
58
|
*/
|
|
34
59
|
delay?: number;
|
|
35
60
|
}
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
export type OgImagePrebuilt = {
|
|
62
|
+
url: string;
|
|
63
|
+
} & Pick<OgImageOptions, 'width' | 'height' | 'alt'>;
|
|
64
|
+
export type DefineOgImageInput = OgImageOptions | OgImagePrebuilt | false;
|
|
65
|
+
export interface OgImageOptions<T extends keyof OgImageComponents = 'NuxtSeo'> {
|
|
66
|
+
/**
|
|
67
|
+
* The width of the screenshot.
|
|
68
|
+
*
|
|
69
|
+
* @default 1200
|
|
70
|
+
*/
|
|
71
|
+
width?: number;
|
|
72
|
+
/**
|
|
73
|
+
* The height of the screenshot.
|
|
74
|
+
*
|
|
75
|
+
* @default 630
|
|
76
|
+
*/
|
|
77
|
+
height?: number;
|
|
78
|
+
/**
|
|
79
|
+
* The alt text for the image.
|
|
80
|
+
*/
|
|
81
|
+
alt?: string;
|
|
40
82
|
/**
|
|
41
|
-
*
|
|
83
|
+
* Use a prebuilt image instead of generating one.
|
|
84
|
+
*
|
|
85
|
+
* Should be an absolute URL.
|
|
42
86
|
*/
|
|
43
|
-
|
|
87
|
+
url?: string;
|
|
88
|
+
/**
|
|
89
|
+
* The name of the component to render.
|
|
90
|
+
*/
|
|
91
|
+
component?: T | string;
|
|
92
|
+
/**
|
|
93
|
+
* Props to pass to the component.
|
|
94
|
+
*/
|
|
95
|
+
props?: OgImageComponents[T] | Record<string, any>;
|
|
96
|
+
renderer?: 'chromium' | 'satori';
|
|
97
|
+
extension?: 'png' | 'jpeg' | 'jpg';
|
|
98
|
+
emojis?: IconifyEmojiIconSets;
|
|
44
99
|
/**
|
|
45
100
|
* Provide a static HTML template to render the OG Image instead of a component.
|
|
46
101
|
*/
|
|
47
102
|
html?: string;
|
|
48
|
-
cache?: boolean;
|
|
49
|
-
cacheKey?: string;
|
|
50
103
|
resvg?: ResvgRenderOptions;
|
|
51
104
|
satori?: SatoriOptions;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
cacheTtl?: number;
|
|
56
|
-
[key: string]: any;
|
|
57
|
-
}
|
|
58
|
-
export interface RuntimeOgImageOptions extends Omit<OgImageOptions, 'extension'> {
|
|
59
|
-
extension: 'png' | 'jpeg' | 'jpg' | 'svg' | 'json' | 'html';
|
|
60
|
-
path: string;
|
|
105
|
+
screenshot?: Partial<ScreenshotOptions>;
|
|
106
|
+
sharp?: SharpOptions;
|
|
107
|
+
cacheMaxAgeSeconds?: number;
|
|
61
108
|
}
|
|
62
109
|
export interface FontConfig {
|
|
63
110
|
name: string;
|
|
64
111
|
weight: string | number;
|
|
65
112
|
path?: string;
|
|
113
|
+
key?: string;
|
|
66
114
|
}
|
|
67
115
|
export type InputFontConfig = (`${string}:${number}` | FontConfig);
|
|
68
|
-
export type RendererOptions = Omit<
|
|
69
|
-
extension: Omit<
|
|
116
|
+
export type RendererOptions = Omit<OgImageOptions, 'extension'> & {
|
|
117
|
+
extension: Omit<OgImageOptions['extension'], 'html'>;
|
|
70
118
|
};
|
|
71
119
|
export interface Renderer {
|
|
72
120
|
name: 'chromium' | 'satori';
|
|
73
121
|
supportedFormats: Partial<RendererOptions['extension']>[];
|
|
74
|
-
createImage: (e:
|
|
122
|
+
createImage: (e: H3EventOgImageRender) => Promise<H3Error | BufferSource | void>;
|
|
123
|
+
debug: (e: H3EventOgImageRender) => Promise<Record<string, any>>;
|
|
75
124
|
}
|
|
76
|
-
export type
|
|
125
|
+
export type ExtractComponentProps<T extends Component> = T extends new (...args: any) => any ? Omit<InstanceType<T>['$props'], keyof ComponentCustomProps | keyof VNodeProps | keyof AllowedComponentProps> : never;
|
|
126
|
+
export type OgImagePageScreenshotOptions = Omit<OgImageOptions, 'html' | 'renderer' | 'component' | 'satori' | 'resvg' | 'sharp'>;
|
|
77
127
|
export type VNode = ReturnType<typeof html>;
|
|
78
128
|
export interface SatoriTransformer {
|
|
79
129
|
filter: (node: VNode) => boolean;
|
|
80
|
-
transform: (node: VNode, e:
|
|
130
|
+
transform: (node: VNode, e: H3EventOgImageRender) => Promise<void>;
|
|
81
131
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { OgImageOptions, OgImageRuntimeConfig } from './types';
|
|
2
|
+
export * from './utils.pure';
|
|
3
|
+
export declare function getOgImagePath(pagePath: string, _options?: Partial<OgImageOptions>): string;
|
|
4
|
+
export declare function useOgImageRuntimeConfig(): OgImageRuntimeConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { joinURL } from "ufo";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
export * from "./utils.pure.mjs";
|
|
5
|
+
export function getOgImagePath(pagePath, _options) {
|
|
6
|
+
const options = defu(_options, useOgImageRuntimeConfig().defaults);
|
|
7
|
+
return joinURL("/__og-image__/image", pagePath, `og.${options.extension}`);
|
|
8
|
+
}
|
|
9
|
+
export function useOgImageRuntimeConfig() {
|
|
10
|
+
return useRuntimeConfig()["nuxt-og-image"];
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defu } from "defu";
|
|
2
|
+
export function isInternalRoute(path) {
|
|
3
|
+
const lastSegment = path.split("/").pop() || path;
|
|
4
|
+
return lastSegment.includes(".") || path.startsWith("/__") || path.startsWith("@");
|
|
5
|
+
}
|
|
6
|
+
function filterIsOgImageOption(key) {
|
|
7
|
+
const keys = [
|
|
8
|
+
"url",
|
|
9
|
+
"extension",
|
|
10
|
+
"width",
|
|
11
|
+
"height",
|
|
12
|
+
"alt",
|
|
13
|
+
"props",
|
|
14
|
+
"renderer",
|
|
15
|
+
"html",
|
|
16
|
+
"component",
|
|
17
|
+
"renderer",
|
|
18
|
+
"emojis",
|
|
19
|
+
"satori",
|
|
20
|
+
"resvg",
|
|
21
|
+
"sharp",
|
|
22
|
+
"screenshot",
|
|
23
|
+
"cacheMaxAgeSeconds",
|
|
24
|
+
"componentHash"
|
|
25
|
+
];
|
|
26
|
+
return keys.includes(key);
|
|
27
|
+
}
|
|
28
|
+
export function separateProps(options, ignoreKeys = []) {
|
|
29
|
+
options = options || {};
|
|
30
|
+
const _props = defu(options.props, Object.fromEntries(
|
|
31
|
+
Object.entries({ ...options }).filter(([k]) => !filterIsOgImageOption(k) && !ignoreKeys.includes(k))
|
|
32
|
+
));
|
|
33
|
+
const props = {};
|
|
34
|
+
Object.entries(_props).forEach(([key, val]) => {
|
|
35
|
+
props[key.replace(/-([a-z])/g, (g) => g[1].toUpperCase())] = val;
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
...Object.fromEntries(
|
|
39
|
+
Object.entries({ ...options }).filter(([k]) => filterIsOgImageOption(k) || ignoreKeys.includes(k))
|
|
40
|
+
),
|
|
41
|
+
props
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.40",
|
|
5
5
|
"packageManager": "pnpm@8.11.0",
|
|
6
6
|
"description": "Enlightened OG Image generation for Nuxt.",
|
|
7
|
+
"author": {
|
|
8
|
+
"website": "https://harlanzw.com",
|
|
9
|
+
"name": "Harlan Wilton",
|
|
10
|
+
"url": "harlan@harlanzw.com"
|
|
11
|
+
},
|
|
7
12
|
"license": "MIT",
|
|
8
13
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
9
14
|
"homepage": "https://github.com/harlan-zw/nuxt-og-image#readme",
|
|
@@ -24,75 +29,68 @@
|
|
|
24
29
|
"main": "./dist/module.cjs",
|
|
25
30
|
"types": "./dist/types.d.ts",
|
|
26
31
|
"files": [
|
|
27
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"virtual.d.ts"
|
|
28
34
|
],
|
|
29
35
|
"dependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@img/sharp-wasm32": "0.33.0-rc.2",
|
|
36
|
+
"@iconify-json/noto": "^1.1.17",
|
|
32
37
|
"@nuxt/devtools-kit": "^1.0.4",
|
|
33
38
|
"@nuxt/kit": "^3.8.2",
|
|
34
39
|
"@resvg/resvg-js": "^2.6.0",
|
|
35
40
|
"@resvg/resvg-wasm": "^2.6.0",
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"chalk": "^5.3.0",
|
|
41
|
+
"@unocss/core": "^0.58.0",
|
|
42
|
+
"@unocss/preset-wind": "^0.58.0",
|
|
43
|
+
"@vueuse/core": "^10.7.0",
|
|
40
44
|
"chrome-launcher": "^1.1.0",
|
|
41
45
|
"css-inline": "^0.11.0",
|
|
42
46
|
"defu": "^6.1.3",
|
|
43
47
|
"execa": "^8.0.1",
|
|
44
|
-
"fast-glob": "^3.3.2",
|
|
45
|
-
"flatted": "^3.2.9",
|
|
46
48
|
"floating-vue": "2.0.0-beta.24",
|
|
47
|
-
"fs-extra": "^11.2.0",
|
|
48
|
-
"globby": "^14.0.0",
|
|
49
49
|
"image-size": "^1.0.2",
|
|
50
|
-
"launch-editor": "^2.6.1",
|
|
51
50
|
"nuxt-site-config": "^1.6.6",
|
|
52
51
|
"nuxt-site-config-kit": "^1.6.6",
|
|
53
52
|
"nypm": "^0.3.3",
|
|
54
53
|
"ofetch": "^1.3.3",
|
|
55
54
|
"ohash": "^1.1.3",
|
|
56
55
|
"pathe": "^1.1.1",
|
|
57
|
-
"playwright-core": "^1.40.
|
|
56
|
+
"playwright-core": "^1.40.1",
|
|
58
57
|
"radix3": "^1.1.0",
|
|
59
58
|
"satori": "0.10.11",
|
|
60
59
|
"satori-html": "^0.3.2",
|
|
61
|
-
"sharp": "0.33.0
|
|
60
|
+
"sharp": "0.33.0",
|
|
62
61
|
"sirv": "^2.0.3",
|
|
63
|
-
"std-env": "^3.
|
|
64
|
-
"svg2png-wasm": "^1.4.1",
|
|
62
|
+
"std-env": "^3.6.0",
|
|
65
63
|
"terminate": "^2.6.1",
|
|
66
|
-
"tinyws": "^0.1.0",
|
|
67
|
-
"twemoji": "^14.0.2",
|
|
68
64
|
"ufo": "^1.3.2",
|
|
69
|
-
"vue-component-meta": "^1.8.22",
|
|
70
|
-
"ws": "^8.14.2",
|
|
71
65
|
"yoga-wasm-web": "^0.3.3"
|
|
72
66
|
},
|
|
73
67
|
"devDependencies": {
|
|
74
|
-
"@antfu/eslint-config": "2.
|
|
75
|
-
"@img/sharp-linux-x64": "0.33.0
|
|
68
|
+
"@antfu/eslint-config": "2.3.4",
|
|
69
|
+
"@img/sharp-linux-x64": "0.33.0",
|
|
76
70
|
"@nuxt/content": "^2.9.0",
|
|
77
71
|
"@nuxt/devtools": "1.0.4",
|
|
78
72
|
"@nuxt/module-builder": "^0.5.4",
|
|
79
73
|
"@nuxt/test-utils": "3.8.1",
|
|
74
|
+
"@nuxt/ui": "^2.11.0",
|
|
80
75
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
81
|
-
"@nuxtjs/i18n": "8.0.0-rc.
|
|
82
|
-
"@
|
|
76
|
+
"@nuxtjs/i18n": "8.0.0-rc.7",
|
|
77
|
+
"@nuxtjs/tailwindcss": "^6.10.1",
|
|
78
|
+
"@unocss/nuxt": "^0.58.0",
|
|
83
79
|
"bumpp": "^9.2.0",
|
|
84
|
-
"eslint": "8.
|
|
85
|
-
"jest-image-snapshot": "^6.
|
|
80
|
+
"eslint": "8.55.0",
|
|
81
|
+
"jest-image-snapshot": "^6.3.0",
|
|
86
82
|
"nuxt": "^3.8.2",
|
|
87
83
|
"nuxt-icon": "0.6.6",
|
|
88
|
-
"playwright": "^1.40.
|
|
84
|
+
"playwright": "^1.40.1",
|
|
89
85
|
"sass": "^1.69.5",
|
|
90
|
-
"vitest": "^0.
|
|
86
|
+
"vitest": "^1.0.1"
|
|
91
87
|
},
|
|
92
88
|
"build": {
|
|
93
89
|
"externals": [
|
|
94
90
|
"h3",
|
|
95
|
-
"nitropack"
|
|
91
|
+
"nitropack",
|
|
92
|
+
"@vue/runtime-core",
|
|
93
|
+
"#nuxt-og-image/components"
|
|
96
94
|
]
|
|
97
95
|
},
|
|
98
96
|
"scripts": {
|
package/virtual.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare module '#nuxt-og-image/components' {
|
|
2
|
+
import type { Component } from 'vue'
|
|
3
|
+
|
|
4
|
+
const components: Record<string, Component>
|
|
5
|
+
export default components
|
|
6
|
+
}
|
|
7
|
+
declare module '#nuxt-og-image/renderers/satori' {
|
|
8
|
+
import type Renderer from './src/runtime/types'
|
|
9
|
+
|
|
10
|
+
const renderer: Renderer | { __unenv__: true } | undefined
|
|
11
|
+
export default renderer
|
|
12
|
+
}
|
|
13
|
+
declare module '#nuxt-og-image/renderers/chromium' {
|
|
14
|
+
import type Renderer from './src/runtime/types'
|
|
15
|
+
|
|
16
|
+
const renderer: Renderer | { __unenv__: true } | undefined
|
|
17
|
+
export default renderer
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare module '#nuxt-og-image/bindings/satori' {
|
|
21
|
+
const satori: typeof import('satori').satori
|
|
22
|
+
export default satori
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare module '#nuxt-og-image/bindings/resvg' {
|
|
26
|
+
interface WasmResvg {
|
|
27
|
+
initWasmPromise: Promise<void>
|
|
28
|
+
Resvg: import('resvg').Resvg
|
|
29
|
+
}
|
|
30
|
+
const instance: WasmResvg
|
|
31
|
+
export default instance
|
|
32
|
+
}
|
|
33
|
+
declare module '#nuxt-og-image/bindings/chromium' {
|
|
34
|
+
export const createBrowser: () => Promise<Browser | void>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare module '#nuxt-og-image/bindings/css-inline' {
|
|
38
|
+
import type _CssInline from 'css-inline'
|
|
39
|
+
|
|
40
|
+
const cssInline: _CssInline
|
|
41
|
+
export default cssInline
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module '#nuxt-og-image/bindings/sharp' {
|
|
45
|
+
import type _sharp from 'sharp'
|
|
46
|
+
|
|
47
|
+
const sharp: _sharp
|
|
48
|
+
export default sharp
|
|
49
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
span[data-v-2408e4e8]{background-color:currentColor;display:inline-block;-webkit-mask-image:var(--f4b1dbd8);mask-image:var(--f4b1dbd8);-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-size:100% 100%;mask-size:100% 100%;vertical-align:middle}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"0ca67bfd-95de-4c16-8f0a-055751cdca51","timestamp":1701183443673,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|