nuxt-og-image 1.4.9 → 1.4.11
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 +11 -10
- package/dist/module.json +1 -1
- package/dist/runtime/composables/defineOgImage.mjs +5 -1
- package/dist/runtime/nitro/renderers/satori/index.mjs +8 -4
- package/dist/runtime/nitro/renderers/satori/utils.d.ts +1 -1
- package/dist/runtime/nitro/renderers/satori/utils.mjs +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,19 +31,20 @@ Enlightened OG Image generation for Nuxt 3.
|
|
|
31
31
|
|
|
32
32
|
ℹ️ Looking for a complete SEO solution? Check out [Nuxt SEO Kit](https://github.com/harlan-zw/nuxt-seo-kit).
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## Features
|
|
35
35
|
|
|
36
|
-
-
|
|
37
|
-
-
|
|
36
|
+
- ✨ Turn your Vue components into `og:image` templates
|
|
37
|
+
- 🎨 Design them in the OG Image Playground with full HMR
|
|
38
|
+
- ▲ Render using [Satori](https://github.com/vercel/satori): Tailwind classes, Google fonts, emoji support and more!
|
|
39
|
+
- 🤖 Or prerender using the Browser: Supporting painless, complex templates
|
|
40
|
+
- 📸 Feeling lazy? Just generate screenshots for every page: hide elements, wait for animations, and more
|
|
41
|
+
- ⚙️ Works on the edge: Vercel Edge and Cloudflare Workers
|
|
38
42
|
|
|
39
|
-
##
|
|
43
|
+
## Demos
|
|
40
44
|
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
- ✨ Prerendering enabled for static images
|
|
45
|
-
- 📸 Feeling lazy? Just generate screenshots with options for hiding elements, waiting for animations, and more
|
|
46
|
-
- ⚙️ Satori support in Vercel Edge and Cloudflare Workers
|
|
45
|
+
- [Vercel Edge Demo](https://nuxt-og-image-playground.vercel.app/)
|
|
46
|
+
- [StackBlitz - Minimal Playground Example](https://stackblitz.com/edit/nuxt-starter-pxs3wk?file=pages/index.vue)
|
|
47
|
+
- [StackBlitz - Alpine Theme](https://stackblitz.com/edit/github-hgunsf?file=package.json)
|
|
47
48
|
|
|
48
49
|
## Install
|
|
49
50
|
|
package/dist/module.json
CHANGED
|
@@ -37,9 +37,13 @@ export function defineOgImage(options = {}) {
|
|
|
37
37
|
e.res.setHeader("x-nitro-prerender", `${route === "/" ? "" : route}/__og_image__/og.png`);
|
|
38
38
|
const meta = [
|
|
39
39
|
{
|
|
40
|
-
|
|
40
|
+
name: "twitter:card",
|
|
41
41
|
content: "summary_large_image"
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
name: "twitter:image:src",
|
|
45
|
+
content: () => withBase(`${route === "/" ? "" : route}/__og_image__/og.png`, host)
|
|
46
|
+
},
|
|
43
47
|
{
|
|
44
48
|
property: "og:image",
|
|
45
49
|
content: () => withBase(`${route === "/" ? "" : route}/__og_image__/og.png`, host)
|
|
@@ -10,6 +10,12 @@ import { fonts, satoriOptions } from "#nuxt-og-image/config";
|
|
|
10
10
|
import loadSvg2png from "#nuxt-og-image/svg2png";
|
|
11
11
|
import loadSatori from "#nuxt-og-image/satori";
|
|
12
12
|
const satoriFonts = [];
|
|
13
|
+
let fontLoadPromise = null;
|
|
14
|
+
function loadFonts(fonts2) {
|
|
15
|
+
if (fontLoadPromise)
|
|
16
|
+
return fontLoadPromise;
|
|
17
|
+
return fontLoadPromise = Promise.all(fonts2.map((font) => loadFont(font)));
|
|
18
|
+
}
|
|
13
19
|
export default {
|
|
14
20
|
name: "satori",
|
|
15
21
|
createPng: async function createPng(baseUrl, options) {
|
|
@@ -39,10 +45,8 @@ export default {
|
|
|
39
45
|
},
|
|
40
46
|
createSvg: async function createSvg(baseUrl, options) {
|
|
41
47
|
const vnodes = await this.createVNode(baseUrl, options);
|
|
42
|
-
if (!satoriFonts.length)
|
|
43
|
-
|
|
44
|
-
satoriFonts.push(await loadFont(new URL(baseUrl), font));
|
|
45
|
-
}
|
|
48
|
+
if (!satoriFonts.length)
|
|
49
|
+
satoriFonts.push(...await loadFonts(fonts));
|
|
46
50
|
const satori = await loadSatori();
|
|
47
51
|
return await satori(vnodes, {
|
|
48
52
|
...satoriOptions,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ParsedURL } from 'ufo';
|
|
2
2
|
import type { SatoriTransformer, VNode } from '../../../../types';
|
|
3
|
-
export declare function loadFont(
|
|
3
|
+
export declare function loadFont(font: string): Promise<any>;
|
|
4
4
|
export declare function walkSatoriTree(url: ParsedURL, node: VNode, plugins: SatoriTransformer[]): Promise<void>;
|
|
5
5
|
export declare function defineSatoriTransformer(transformer: (url: ParsedURL) => SatoriTransformer): (url: ParsedURL) => SatoriTransformer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { base64ToArrayBuffer, readPublicAsset } from "../../utils.mjs";
|
|
2
2
|
import { useStorage } from "#internal/nitro";
|
|
3
3
|
const cachedFonts = {};
|
|
4
|
-
export async function loadFont(
|
|
4
|
+
export async function loadFont(font) {
|
|
5
5
|
if (cachedFonts[font])
|
|
6
6
|
return cachedFonts[font];
|
|
7
7
|
let data;
|
|
@@ -14,7 +14,7 @@ export async function loadFont(url, font) {
|
|
|
14
14
|
if (name === "Inter" && ["400", "700"].includes(weight)) {
|
|
15
15
|
const data2 = await readPublicAsset(`/inter-latin-ext-${weight}-normal.woff`);
|
|
16
16
|
if (data2)
|
|
17
|
-
return cachedFonts[font] = { name:
|
|
17
|
+
return cachedFonts[font] = { name, weight: Number(weight), data: data2, style: "normal" };
|
|
18
18
|
}
|
|
19
19
|
if (!data) {
|
|
20
20
|
const fontUrl = await globalThis.$fetch("/api/og-image-font", {
|
|
@@ -25,7 +25,7 @@ export async function loadFont(url, font) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
await useStorage().setItem(storageKey, Buffer.from(data).toString("base64"));
|
|
28
|
-
return cachedFonts[font] = { name, weight, data, style: "normal" };
|
|
28
|
+
return cachedFonts[font] = { name, weight: Number(weight), data, style: "normal" };
|
|
29
29
|
}
|
|
30
30
|
export async function walkSatoriTree(url, node, plugins) {
|
|
31
31
|
if (!node.props?.children)
|