nuxt-og-image 2.2.4 → 3.0.0-beta.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/README.md +2 -2
- package/dist/client/200.html +8 -8
- package/dist/client/404.html +8 -8
- package/dist/client/_nuxt/IconCSS.8f429b14.css +1 -0
- package/dist/client/_nuxt/IconCSS.ac398b56.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/d1d517c3-4927-4803-bbb0-d94e9d3e9581.json +1 -0
- package/dist/client/_nuxt/entry.434c2c45.css +1 -0
- package/dist/client/_nuxt/entry.bdb8a8d5.js +137 -0
- package/dist/client/_nuxt/{error-404.407d76a3.js → error-404.f37119e7.js} +1 -1
- package/dist/client/_nuxt/{error-500.531c4147.js → error-500.74b0a30f.js} +1 -1
- package/dist/client/grid.png +0 -0
- package/dist/client/index.html +8 -8
- package/dist/module.d.mts +43 -39
- package/dist/module.d.ts +43 -39
- package/dist/module.json +1 -1
- package/dist/module.mjs +341 -667
- package/dist/runtime/cache.d.ts +4 -4
- package/dist/runtime/cache.mjs +2 -1
- package/dist/runtime/components/OgImage/Cached.mjs +1 -1
- package/dist/runtime/components/OgImage/Dynamic.mjs +1 -1
- package/dist/runtime/components/OgImage/Screenshot.mjs +1 -1
- package/dist/runtime/components/OgImage/Static.mjs +1 -1
- package/dist/runtime/components/OgImage/WithoutCache.mjs +1 -1
- package/dist/runtime/components/OgImage/index.mjs +1 -1
- package/dist/runtime/components/Templates/Community/Nuxt.vue +183 -0
- package/dist/runtime/components/Templates/Official/BrandedLogo.vue +28 -0
- package/dist/runtime/components/Templates/Official/Fallback.vue +147 -0
- package/dist/runtime/components/Templates/Official/SimpleBlog.vue +33 -0
- package/dist/runtime/components/Templates/Official/Wave.vue +33 -0
- package/dist/runtime/components/Templates/Official/WithEmoji.vue +27 -0
- package/dist/runtime/composables/defineOgImage.d.ts +10 -6
- package/dist/runtime/composables/defineOgImage.mjs +21 -9
- package/dist/runtime/core/bindings/chromium/node.d.ts +2 -0
- package/dist/runtime/{nitro/providers/browser/universal.mjs → core/bindings/chromium/node.mjs} +3 -3
- package/dist/runtime/core/bindings/resvg/node.d.ts +6 -0
- package/dist/runtime/core/bindings/resvg/node.mjs +5 -0
- package/dist/runtime/core/bindings/resvg/wasm.d.ts +40 -0
- package/dist/runtime/core/bindings/resvg/wasm.mjs +7 -0
- package/dist/runtime/core/bindings/satori/node.d.ts +6 -0
- package/dist/runtime/core/bindings/satori/node.mjs +5 -0
- package/dist/runtime/core/bindings/satori/yoga-wasm.d.ts +6 -0
- package/dist/runtime/core/bindings/satori/yoga-wasm.mjs +7 -0
- package/dist/runtime/core/bindings/sharp/node.d.ts +2 -0
- package/dist/runtime/core/bindings/sharp/node.mjs +2 -0
- package/dist/runtime/core/bindings/sharp/wasm.d.ts +2 -0
- package/dist/runtime/core/bindings/sharp/wasm.mjs +2 -0
- package/dist/runtime/core/cache/prerender.d.ts +6 -0
- package/dist/runtime/core/cache/prerender.mjs +6 -0
- package/dist/runtime/core/env/assets.d.ts +2 -0
- package/dist/runtime/core/env/assets.mjs +15 -0
- package/dist/runtime/core/font/cache.d.ts +1 -0
- package/dist/runtime/core/font/cache.mjs +1 -0
- package/dist/runtime/core/font/fetch.d.ts +3 -0
- package/dist/runtime/core/font/fetch.mjs +29 -0
- package/dist/runtime/core/html/fetch.d.ts +3 -0
- package/dist/runtime/core/html/fetch.mjs +117 -0
- package/dist/runtime/core/options/extract.d.ts +3 -0
- package/dist/runtime/{nitro/utils-pure.mjs → core/options/extract.mjs} +23 -21
- package/dist/runtime/core/options/fetch.d.ts +3 -0
- package/dist/runtime/core/options/fetch.mjs +21 -0
- package/dist/runtime/core/options/normalise.d.ts +2 -0
- package/dist/runtime/{composables/util.mjs → core/options/normalise.mjs} +9 -6
- package/dist/runtime/core/renderers/chromium/index.d.ts +3 -0
- package/dist/runtime/core/renderers/chromium/index.mjs +26 -0
- package/dist/runtime/core/renderers/chromium/screenshot.d.ts +6 -0
- package/dist/runtime/core/renderers/chromium/screenshot.mjs +47 -0
- package/dist/runtime/core/renderers/satori/fonts.d.ts +3 -0
- package/dist/runtime/core/renderers/satori/fonts.mjs +8 -0
- package/dist/runtime/core/renderers/satori/index.d.ts +5 -0
- package/dist/runtime/core/renderers/satori/index.mjs +53 -0
- package/dist/runtime/core/renderers/satori/instances.d.ts +39 -0
- package/dist/runtime/core/renderers/satori/instances.mjs +17 -0
- package/dist/runtime/{nitro → core}/renderers/satori/plugins/encoding.mjs +1 -1
- package/dist/runtime/{nitro → core}/renderers/satori/plugins/imageSrc.mjs +9 -14
- package/dist/runtime/{nitro → core}/renderers/satori/plugins/twClasses.mjs +1 -0
- package/dist/runtime/core/renderers/satori/utils.d.ts +4 -0
- package/dist/runtime/core/renderers/satori/utils.mjs +20 -0
- package/dist/runtime/core/renderers/satori/vnodes.d.ts +3 -0
- package/dist/runtime/core/renderers/satori/vnodes.mjs +21 -0
- package/dist/runtime/core/utils/resolveRendererContext.d.ts +7 -0
- package/dist/runtime/core/utils/resolveRendererContext.mjs +76 -0
- package/dist/runtime/nitro/plugins/nuxt-content.d.ts +2 -0
- package/dist/runtime/nitro/plugins/nuxt-content.mjs +50 -0
- package/dist/runtime/nitro/plugins/prerender.d.ts +2 -3
- package/dist/runtime/nitro/plugins/prerender.mjs +25 -33
- package/dist/runtime/nuxt/plugins/nuxt-content-canonical-urls.mjs +29 -0
- package/dist/runtime/nuxt/plugins/route-rule-og-image.server.d.ts +2 -0
- package/dist/runtime/nuxt/plugins/route-rule-og-image.server.mjs +72 -0
- package/dist/runtime/{nitro/routes/debug.d.ts → server/routes/__og-image__/debug.json.d.ts} +1 -1
- package/dist/runtime/{nitro/routes/debug.mjs → server/routes/__og-image__/debug.json.mjs} +3 -2
- package/dist/runtime/server/routes/__og-image__/font-[name]-[weight].[extension].mjs +30 -0
- package/dist/runtime/server/routes/__og-image__/image-[path]-og.[extension].mjs +44 -0
- package/dist/runtime/types.d.ts +29 -24
- package/dist/runtime/utilts.d.ts +2 -0
- package/dist/runtime/utilts.mjs +8 -0
- package/dist/types.d.mts +3 -2
- package/dist/types.d.ts +3 -2
- package/package.json +37 -22
- package/dist/client/_nuxt/IconCSS.4a9d43d0.css +0 -1
- package/dist/client/_nuxt/IconCSS.9c30257a.js +0 -1
- package/dist/client/_nuxt/ImageLoader.752b0c7a.js +0 -1
- package/dist/client/_nuxt/ImageLoader.7571516f.css +0 -1
- package/dist/client/_nuxt/builds/meta/bb64bb30-cf6f-4625-97ba-06e6a0d3f8d1.json +0 -1
- package/dist/client/_nuxt/entry.39e39f51.css +0 -1
- package/dist/client/_nuxt/entry.ac864471.js +0 -135
- package/dist/client/_nuxt/index.dc1538d5.js +0 -1
- package/dist/client/_nuxt/index.ffbea0a9.css +0 -1
- package/dist/client/_nuxt/options.a77f5921.js +0 -1
- package/dist/client/_nuxt/png.41e0b446.js +0 -1
- package/dist/client/_nuxt/shiki.d4e62362.js +0 -7
- package/dist/client/_nuxt/svg.b8198280.js +0 -1
- package/dist/client/_nuxt/vnodes.67720126.js +0 -1
- package/dist/client/options/index.html +0 -15
- package/dist/client/png/index.html +0 -15
- package/dist/client/svg/index.html +0 -15
- package/dist/client/vnodes/index.html +0 -15
- package/dist/runtime/browserUtil.d.ts +0 -5
- package/dist/runtime/browserUtil.mjs +0 -41
- package/dist/runtime/components/OgImageTemplate/Fallback.vue +0 -161
- package/dist/runtime/composables/util.d.ts +0 -2
- package/dist/runtime/nitro/middleware/og.png.mjs +0 -69
- package/dist/runtime/nitro/middleware/playground.d.ts +0 -2
- package/dist/runtime/nitro/middleware/playground.mjs +0 -27
- package/dist/runtime/nitro/providers/browser/lambda.d.ts +0 -1
- package/dist/runtime/nitro/providers/browser/lambda.mjs +0 -9
- package/dist/runtime/nitro/providers/browser/playwright.d.ts +0 -1
- package/dist/runtime/nitro/providers/browser/playwright.mjs +0 -22
- package/dist/runtime/nitro/providers/browser/universal.d.ts +0 -2
- package/dist/runtime/nitro/providers/png/resvg-node.d.ts +0 -4
- package/dist/runtime/nitro/providers/png/resvg-node.mjs +0 -6
- package/dist/runtime/nitro/providers/png/resvg-wasm.d.ts +0 -3
- package/dist/runtime/nitro/providers/png/resvg-wasm.mjs +0 -11
- package/dist/runtime/nitro/providers/png/svg2png.d.ts +0 -3
- package/dist/runtime/nitro/providers/png/svg2png.mjs +0 -11
- package/dist/runtime/nitro/providers/satori/default.d.ts +0 -2
- package/dist/runtime/nitro/providers/satori/default.mjs +0 -4
- package/dist/runtime/nitro/providers/satori/yoga-wasm.d.ts +0 -3
- package/dist/runtime/nitro/providers/satori/yoga-wasm.mjs +0 -10
- package/dist/runtime/nitro/renderers/browser.d.ts +0 -3
- package/dist/runtime/nitro/renderers/browser.mjs +0 -36
- package/dist/runtime/nitro/renderers/satori/index.d.ts +0 -3
- package/dist/runtime/nitro/renderers/satori/index.mjs +0 -58
- package/dist/runtime/nitro/renderers/satori/utils.d.ts +0 -4
- package/dist/runtime/nitro/renderers/satori/utils.mjs +0 -60
- package/dist/runtime/nitro/routes/font.mjs +0 -22
- package/dist/runtime/nitro/routes/html.d.ts +0 -2
- package/dist/runtime/nitro/routes/html.mjs +0 -178
- package/dist/runtime/nitro/routes/options.d.ts +0 -3
- package/dist/runtime/nitro/routes/options.mjs +0 -35
- package/dist/runtime/nitro/routes/svg.mjs +0 -19
- package/dist/runtime/nitro/routes/vnode.d.ts +0 -2
- package/dist/runtime/nitro/routes/vnode.mjs +0 -19
- package/dist/runtime/nitro/utils-pure.d.ts +0 -3
- package/dist/runtime/nitro/utils.d.ts +0 -18
- package/dist/runtime/nitro/utils.mjs +0 -108
- package/dist/runtime/public-assets-optional/resvg/resvg.wasm +0 -0
- package/dist/runtime/public-assets-optional/svg2png/svg2png.wasm +0 -0
- package/dist/runtime/public-assets-optional/yoga/yoga.wasm +0 -0
- /package/dist/runtime/{nitro/providers → core/bindings}/css-inline/mock.d.ts +0 -0
- /package/dist/runtime/{nitro/providers → core/bindings}/css-inline/mock.mjs +0 -0
- /package/dist/runtime/{nitro/providers/css-inline/css-inline.d.ts → core/bindings/css-inline/node.d.ts} +0 -0
- /package/dist/runtime/{nitro/providers/css-inline/css-inline.mjs → core/bindings/css-inline/node.mjs} +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/emojis.d.ts +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/emojis.mjs +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/encoding.d.ts +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/flex.d.ts +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/flex.mjs +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/imageSrc.d.ts +0 -0
- /package/dist/runtime/{nitro → core}/renderers/satori/plugins/twClasses.d.ts +0 -0
- /package/dist/runtime/{nitro/routes/font.d.ts → nuxt/plugins/nuxt-content-canonical-urls.d.ts} +0 -0
- /package/dist/runtime/{nitro/middleware/og.png.d.ts → server/routes/__og-image__/font-[name]-[weight].[extension].d.ts} +0 -0
- /package/dist/runtime/{nitro/routes/svg.d.ts → server/routes/__og-image__/image-[path]-og.[extension].d.ts} +0 -0
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { withBase } from "ufo";
|
|
2
|
-
import { renderSSRHead } from "@unhead/ssr";
|
|
3
|
-
import { createHeadCore } from "@unhead/vue";
|
|
4
|
-
import { createError, defineEventHandler, getQuery, sendRedirect } from "h3";
|
|
5
|
-
import { hash } from "ohash";
|
|
6
|
-
import twemoji from "twemoji";
|
|
7
|
-
import { createDefu } from "defu";
|
|
8
|
-
import { fetchOptionsCached } from "../utils.mjs";
|
|
9
|
-
import { useNitroOrigin, useRuntimeConfig } from "#imports";
|
|
10
|
-
import loadCSSInline from "#nuxt-og-image/css-inline";
|
|
11
|
-
export default defineEventHandler(async (e) => {
|
|
12
|
-
const { fonts, satoriOptions } = useRuntimeConfig()["nuxt-og-image"];
|
|
13
|
-
const query = getQuery(e);
|
|
14
|
-
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
15
|
-
const scale = query.scale;
|
|
16
|
-
const mode = query.mode || "light";
|
|
17
|
-
const nitroOrigin = useNitroOrigin(e);
|
|
18
|
-
let queryOptions;
|
|
19
|
-
if (query.options) {
|
|
20
|
-
try {
|
|
21
|
-
queryOptions = JSON.parse(query.options);
|
|
22
|
-
} catch {
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
let options = await fetchOptionsCached(e, path);
|
|
26
|
-
const merger = createDefu((object, key, value) => {
|
|
27
|
-
if (Array.isArray(value))
|
|
28
|
-
return value;
|
|
29
|
-
});
|
|
30
|
-
if (queryOptions)
|
|
31
|
-
options = merger(queryOptions, options);
|
|
32
|
-
if (options.provider === "browser" && options.component === "PageScreenshot") {
|
|
33
|
-
const pathWithoutBase = path.replace(new RegExp(`^${useRuntimeConfig().app.baseURL}`), "");
|
|
34
|
-
return sendRedirect(e, withBase(pathWithoutBase, nitroOrigin));
|
|
35
|
-
}
|
|
36
|
-
if (!options.component) {
|
|
37
|
-
throw createError({
|
|
38
|
-
statusCode: 500,
|
|
39
|
-
statusMessage: `Nuxt OG Image trying to render an invalid component. Received options ${JSON.stringify(options)}`
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const hashId = hash([options.component, options]);
|
|
43
|
-
const island = await $fetch(`/__nuxt_island/${options.component}_${hashId}`, {
|
|
44
|
-
params: {
|
|
45
|
-
props: JSON.stringify(options)
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
const head = createHeadCore();
|
|
49
|
-
head.push(island.head);
|
|
50
|
-
let defaultFontFamily = "sans-serif";
|
|
51
|
-
const firstFont = fonts[0];
|
|
52
|
-
if (firstFont)
|
|
53
|
-
defaultFontFamily = firstFont.name;
|
|
54
|
-
let html = island.html;
|
|
55
|
-
try {
|
|
56
|
-
html = twemoji.parse(html, {
|
|
57
|
-
folder: "svg",
|
|
58
|
-
ext: ".svg"
|
|
59
|
-
});
|
|
60
|
-
} catch (e2) {
|
|
61
|
-
}
|
|
62
|
-
const googleFonts = {};
|
|
63
|
-
fonts.filter((font) => !font.path).forEach((font) => {
|
|
64
|
-
if (!googleFonts[font.name])
|
|
65
|
-
googleFonts[font.name] = [];
|
|
66
|
-
googleFonts[font.name].push(font);
|
|
67
|
-
});
|
|
68
|
-
head.push({
|
|
69
|
-
style: [
|
|
70
|
-
{
|
|
71
|
-
// default font is the first font family
|
|
72
|
-
innerHTML: `body { font-family: '${defaultFontFamily.replace("+", " ")}', sans-serif; }`
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
innerHTML: `body {
|
|
76
|
-
transform: scale(${scale || 1});
|
|
77
|
-
transform-origin: top left;
|
|
78
|
-
max-height: 100vh;
|
|
79
|
-
position: relative;
|
|
80
|
-
width: ${options.width}px;
|
|
81
|
-
height: ${options.height}px;
|
|
82
|
-
overflow: hidden;
|
|
83
|
-
background-color: ${mode === "dark" ? "#1b1b1b" : "#fff"};
|
|
84
|
-
}
|
|
85
|
-
img.emoji {
|
|
86
|
-
height: 1em;
|
|
87
|
-
width: 1em;
|
|
88
|
-
margin: 0 .05em 0 .1em;
|
|
89
|
-
vertical-align: -0.1em;
|
|
90
|
-
}`
|
|
91
|
-
},
|
|
92
|
-
...fonts.filter((font) => font.path).map((font) => {
|
|
93
|
-
return `
|
|
94
|
-
@font-face {
|
|
95
|
-
font-family: '${font.name}';
|
|
96
|
-
font-style: normal;
|
|
97
|
-
font-weight: ${font.weight};
|
|
98
|
-
src: url('${font.path}') format('truetype');
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
})
|
|
102
|
-
],
|
|
103
|
-
meta: [
|
|
104
|
-
{
|
|
105
|
-
charset: "utf-8"
|
|
106
|
-
}
|
|
107
|
-
],
|
|
108
|
-
script: [
|
|
109
|
-
{
|
|
110
|
-
src: "https://cdn.tailwindcss.com"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
innerHTML: `tailwind.config = {
|
|
114
|
-
corePlugins: {
|
|
115
|
-
preflight: false,
|
|
116
|
-
},
|
|
117
|
-
theme: ${JSON.stringify(satoriOptions?.tailwindConfig?.theme || {})}
|
|
118
|
-
}`
|
|
119
|
-
}
|
|
120
|
-
],
|
|
121
|
-
link: [
|
|
122
|
-
{
|
|
123
|
-
// reset css to match svg output
|
|
124
|
-
href: "https://cdn.jsdelivr.net/npm/gardevoir",
|
|
125
|
-
rel: "stylesheet"
|
|
126
|
-
},
|
|
127
|
-
// have to add each weight as their own stylesheet
|
|
128
|
-
...Object.entries(googleFonts).map(([name, fonts2]) => {
|
|
129
|
-
return {
|
|
130
|
-
href: `https://fonts.googleapis.com/css2?family=${name}:wght@${fonts2.map((f) => f.weight).join(";")}&display=swap`,
|
|
131
|
-
rel: "stylesheet"
|
|
132
|
-
};
|
|
133
|
-
})
|
|
134
|
-
]
|
|
135
|
-
});
|
|
136
|
-
html = html.replaceAll(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
|
|
137
|
-
const headChunk = await renderSSRHead(head);
|
|
138
|
-
let htmlTemplate = `<!DOCTYPE html>
|
|
139
|
-
<html ${headChunk.htmlAttrs}>
|
|
140
|
-
<head>${headChunk.headTags}</head>
|
|
141
|
-
<body ${headChunk.bodyAttrs}>${headChunk.bodyTagsOpen}<div style="position: relative; display: flex; margin: 0 auto; width: ${options.width}px; height: ${options.height}px; overflow: hidden;">${html}</div>${headChunk.bodyTags}</body>
|
|
142
|
-
</html>`;
|
|
143
|
-
const cssInline = loadCSSInline();
|
|
144
|
-
if (!cssInline.__mock) {
|
|
145
|
-
let hasInlineStyles = false;
|
|
146
|
-
const stylesheets = htmlTemplate.match(/<link rel="stylesheet" href=".*?">/g);
|
|
147
|
-
if (stylesheets) {
|
|
148
|
-
for (const stylesheet of stylesheets) {
|
|
149
|
-
if (!stylesheet.includes(`${options.component.replace("OgImageTemplate", "").replace("OgImage", "")}.vue`)) {
|
|
150
|
-
htmlTemplate = htmlTemplate.replace(stylesheet, "");
|
|
151
|
-
} else {
|
|
152
|
-
const href = stylesheet.match(/href="(.*?)"/)[1];
|
|
153
|
-
try {
|
|
154
|
-
let css = await (await $fetch(href, {
|
|
155
|
-
baseURL: nitroOrigin
|
|
156
|
-
})).text();
|
|
157
|
-
if (css.includes("const __vite__css =")) {
|
|
158
|
-
css = css.match(/const __vite__css = "(.*)"/)[1].replace(/\\n/g, "\n");
|
|
159
|
-
}
|
|
160
|
-
css = css.replace(/\/\*# sourceMappingURL=.*?\*\//g, "").replaceAll("! important", "").replaceAll("!important");
|
|
161
|
-
htmlTemplate = htmlTemplate.replace(stylesheet, `<style>${css}</style>`);
|
|
162
|
-
hasInlineStyles = true;
|
|
163
|
-
} catch {
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (hasInlineStyles) {
|
|
169
|
-
try {
|
|
170
|
-
htmlTemplate = await cssInline(htmlTemplate, {
|
|
171
|
-
url: nitroOrigin
|
|
172
|
-
});
|
|
173
|
-
} catch {
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return htmlTemplate;
|
|
178
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createError, defineEventHandler, getQuery } from "h3";
|
|
2
|
-
import { withoutBase } from "ufo";
|
|
3
|
-
import { extractAndNormaliseOgImageOptions } from "../utils.mjs";
|
|
4
|
-
import { getRouteRules } from "#internal/nitro";
|
|
5
|
-
import { useRuntimeConfig } from "#imports";
|
|
6
|
-
export default defineEventHandler(async (e) => {
|
|
7
|
-
const query = getQuery(e);
|
|
8
|
-
const path = withoutBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
9
|
-
let html;
|
|
10
|
-
try {
|
|
11
|
-
html = await globalThis.$fetch(path);
|
|
12
|
-
} catch (err) {
|
|
13
|
-
throw createError({
|
|
14
|
-
statusCode: 500,
|
|
15
|
-
statusMessage: `Failed to read the path ${path} for og-image extraction. ${err.message}.`
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
e.node.req.url = path;
|
|
19
|
-
const oldRouteRules = e.context._nitro.routeRules;
|
|
20
|
-
e.context._nitro.routeRules = void 0;
|
|
21
|
-
const routeRules = getRouteRules(e)?.ogImage || {};
|
|
22
|
-
e.context._nitro.routeRules = oldRouteRules;
|
|
23
|
-
e.node.req.url = e.path;
|
|
24
|
-
if (routeRules === false)
|
|
25
|
-
return false;
|
|
26
|
-
const { defaults } = useRuntimeConfig()["nuxt-og-image"];
|
|
27
|
-
const payload = extractAndNormaliseOgImageOptions(path, html, routeRules, defaults);
|
|
28
|
-
if (!payload) {
|
|
29
|
-
throw createError({
|
|
30
|
-
statusCode: 500,
|
|
31
|
-
statusMessage: `The path ${path} is missing the og-image payload.`
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return payload;
|
|
35
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
2
|
-
import { withBase } from "ufo";
|
|
3
|
-
import { fetchOptionsCached } from "../utils.mjs";
|
|
4
|
-
import { useProvider } from "#nuxt-og-image/provider";
|
|
5
|
-
import { useRuntimeConfig } from "#imports";
|
|
6
|
-
export default defineEventHandler(async (e) => {
|
|
7
|
-
const query = getQuery(e);
|
|
8
|
-
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
9
|
-
const options = await fetchOptionsCached(e, path);
|
|
10
|
-
setHeader(e, "Content-Type", "image/svg+xml");
|
|
11
|
-
const provider = await useProvider(options.provider);
|
|
12
|
-
if (!provider) {
|
|
13
|
-
throw createError({
|
|
14
|
-
statusCode: 500,
|
|
15
|
-
statusMessage: `Provider ${options.provider} is missing.`
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return provider.createSvg(options);
|
|
19
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
2
|
-
import { withBase } from "ufo";
|
|
3
|
-
import { fetchOptionsCached } from "../utils.mjs";
|
|
4
|
-
import { useProvider } from "#nuxt-og-image/provider";
|
|
5
|
-
import { useRuntimeConfig } from "#imports";
|
|
6
|
-
export default defineEventHandler(async (e) => {
|
|
7
|
-
const query = getQuery(e);
|
|
8
|
-
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
9
|
-
const options = await fetchOptionsCached(e, path);
|
|
10
|
-
setHeader(e, "Content-Type", "application/json");
|
|
11
|
-
const provider = await useProvider(options.provider);
|
|
12
|
-
if (!provider) {
|
|
13
|
-
throw createError({
|
|
14
|
-
statusCode: 500,
|
|
15
|
-
statusMessage: `Provider ${options.provider} is missing.`
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return provider.createVNode(options);
|
|
19
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Buffer } from 'node:buffer';
|
|
3
|
-
import type { H3Event } from 'h3';
|
|
4
|
-
import type { RuntimeOgImageOptions } from '../types';
|
|
5
|
-
export declare function wasmLoader(asyncModuleLoad: Promise<any> | Buffer | string, fallback: string): {
|
|
6
|
-
load(options: RuntimeOgImageOptions): Promise<any>;
|
|
7
|
-
};
|
|
8
|
-
export declare function fetchOptionsCached(e: H3Event, path: string): Promise<RuntimeOgImageOptions>;
|
|
9
|
-
export declare function fetchOptions(e: H3Event, path: string): Promise<RuntimeOgImageOptions>;
|
|
10
|
-
export declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
|
|
11
|
-
export declare function readPublicAsset(file: string, encoding?: BufferEncoding): Promise<string | Buffer | undefined>;
|
|
12
|
-
export declare function readPublicAssetBase64(file: string): Promise<{
|
|
13
|
-
src: string;
|
|
14
|
-
width?: number;
|
|
15
|
-
height?: number;
|
|
16
|
-
} | undefined>;
|
|
17
|
-
export declare function toBase64Image(fileName: string, data: string | ArrayBuffer): string;
|
|
18
|
-
export * from './utils-pure';
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises as fsp } from "node:fs";
|
|
2
|
-
import { Buffer } from "node:buffer";
|
|
3
|
-
import { getQuery } from "h3";
|
|
4
|
-
import { join } from "pathe";
|
|
5
|
-
import sizeOf from "image-size";
|
|
6
|
-
import { defu } from "defu";
|
|
7
|
-
import { withoutLeadingSlash } from "ufo";
|
|
8
|
-
import { useNitroCache } from "../cache.mjs";
|
|
9
|
-
import { useNitroOrigin, useRuntimeConfig } from "#imports";
|
|
10
|
-
export function wasmLoader(asyncModuleLoad, fallback) {
|
|
11
|
-
let promise;
|
|
12
|
-
let wasm;
|
|
13
|
-
return {
|
|
14
|
-
async load(options) {
|
|
15
|
-
if (typeof promise !== "undefined")
|
|
16
|
-
return promise;
|
|
17
|
-
if (wasm)
|
|
18
|
-
return wasm;
|
|
19
|
-
promise = promise || new Promise(async (resolve) => {
|
|
20
|
-
try {
|
|
21
|
-
wasm = await asyncModuleLoad;
|
|
22
|
-
if (typeof wasm === "string")
|
|
23
|
-
wasm = void 0;
|
|
24
|
-
} catch (e) {
|
|
25
|
-
}
|
|
26
|
-
if (!wasm) {
|
|
27
|
-
wasm = await readPublicAsset(fallback, "base64");
|
|
28
|
-
if (wasm)
|
|
29
|
-
wasm = Buffer.from(wasm, "base64");
|
|
30
|
-
}
|
|
31
|
-
if (!wasm) {
|
|
32
|
-
wasm = await (await globalThis.$fetch(fallback, { baseURL: options.requestOrigin })).arrayBuffer();
|
|
33
|
-
wasm = Buffer.from(wasm);
|
|
34
|
-
}
|
|
35
|
-
resolve(wasm);
|
|
36
|
-
});
|
|
37
|
-
return promise;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export async function fetchOptionsCached(e, path) {
|
|
42
|
-
const key = [
|
|
43
|
-
withoutLeadingSlash(path === "/" || !path ? "index" : path).replaceAll("/", "-"),
|
|
44
|
-
"options"
|
|
45
|
-
].join(":");
|
|
46
|
-
const { cachedItem, update } = await useNitroCache(e, "nuxt-og-image", {
|
|
47
|
-
key,
|
|
48
|
-
// allow internal requests to be cached for 5 seconds
|
|
49
|
-
cacheTtl: 5 * 1e3,
|
|
50
|
-
cache: !process.dev,
|
|
51
|
-
headers: false
|
|
52
|
-
});
|
|
53
|
-
if (cachedItem)
|
|
54
|
-
return cachedItem;
|
|
55
|
-
const options = await fetchOptions(e, path);
|
|
56
|
-
await update(options);
|
|
57
|
-
return options;
|
|
58
|
-
}
|
|
59
|
-
export async function fetchOptions(e, path) {
|
|
60
|
-
const options = await globalThis.$fetch("/api/og-image-options", {
|
|
61
|
-
query: {
|
|
62
|
-
path
|
|
63
|
-
},
|
|
64
|
-
responseType: "json"
|
|
65
|
-
});
|
|
66
|
-
return defu(
|
|
67
|
-
{ requestOrigin: useNitroOrigin(e) },
|
|
68
|
-
options,
|
|
69
|
-
// use query data
|
|
70
|
-
getQuery(e)
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
export function base64ToArrayBuffer(base64) {
|
|
74
|
-
const buffer = Buffer.from(base64, "base64");
|
|
75
|
-
return new Uint8Array(buffer).buffer;
|
|
76
|
-
}
|
|
77
|
-
function r(base, key) {
|
|
78
|
-
return join(base, key.replace(/:/g, "/"));
|
|
79
|
-
}
|
|
80
|
-
export async function readPublicAsset(file, encoding) {
|
|
81
|
-
const { assetDirs } = useRuntimeConfig()["nuxt-og-image"];
|
|
82
|
-
for (const assetDir of assetDirs) {
|
|
83
|
-
const path = r(assetDir, file);
|
|
84
|
-
if (existsSync(path))
|
|
85
|
-
return await fsp.readFile(path, { encoding });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export async function readPublicAssetBase64(file) {
|
|
89
|
-
const base64 = await readPublicAsset(file, "base64");
|
|
90
|
-
if (base64) {
|
|
91
|
-
const dimensions = await sizeOf(Buffer.from(base64, "base64"));
|
|
92
|
-
return {
|
|
93
|
-
src: toBase64Image(file, base64),
|
|
94
|
-
...dimensions
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export function toBase64Image(fileName, data) {
|
|
99
|
-
const base64 = typeof data === "string" ? data : Buffer.from(data).toString("base64");
|
|
100
|
-
let type = "image/jpeg";
|
|
101
|
-
const ext = fileName.split(".").pop();
|
|
102
|
-
if (ext === "svg")
|
|
103
|
-
type = "image/svg+xml";
|
|
104
|
-
else if (ext === "png")
|
|
105
|
-
type = "image/png";
|
|
106
|
-
return `data:${type};base64,${base64}`;
|
|
107
|
-
}
|
|
108
|
-
export * from "./utils-pure.mjs";
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/runtime/{nitro/routes/font.d.ts → nuxt/plugins/nuxt-content-canonical-urls.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|