nuxt-og-image 0.5.2 → 0.5.4
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 +3 -4
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +6 -5
- package/dist/runtime/composables/defineOgImage.mjs +21 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Generate dynamic social share images for you Nuxt v3 app.
|
|
|
34
34
|
- 📸 OR just generate screenshots
|
|
35
35
|
- 📦 Choose your API: Composition or components
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
🔨 Edge rendering is coming soon!
|
|
38
38
|
|
|
39
39
|
## Install
|
|
40
40
|
|
|
@@ -97,8 +97,7 @@ export default defineNuxtConfig({
|
|
|
97
97
|
|
|
98
98
|
### Pre-render routes
|
|
99
99
|
|
|
100
|
-
While the module is in early access,
|
|
101
|
-
generate images for.
|
|
100
|
+
While the module is in early access, only pre-rendered routes are supported.
|
|
102
101
|
|
|
103
102
|
```ts
|
|
104
103
|
export default defineNuxtConfig({
|
|
@@ -250,7 +249,7 @@ the following URLs:
|
|
|
250
249
|
|
|
251
250
|
The host of your site. This is required to generate the absolute path of the og:image.
|
|
252
251
|
|
|
253
|
-
### `
|
|
252
|
+
### `serverSideRender`
|
|
254
253
|
|
|
255
254
|
- Type: `boolean`
|
|
256
255
|
- Default: `process.dev`
|
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -81,7 +81,7 @@ const module = defineNuxtModule({
|
|
|
81
81
|
height: 630,
|
|
82
82
|
defaultIslandComponent: "OgImageTemplate",
|
|
83
83
|
outputDir: "_og-images",
|
|
84
|
-
|
|
84
|
+
serverSideRender: nuxt.options.dev || (process.env.NITRO_PRESET || "").includes("edge")
|
|
85
85
|
};
|
|
86
86
|
},
|
|
87
87
|
async setup(config, nuxt) {
|
|
@@ -107,7 +107,7 @@ declare module 'nitropack' {
|
|
|
107
107
|
addServerHandler({
|
|
108
108
|
handler: resolve("./runtime/nitro/html")
|
|
109
109
|
});
|
|
110
|
-
if (config.
|
|
110
|
+
if (config.serverSideRender) {
|
|
111
111
|
addServerHandler({
|
|
112
112
|
handler: resolve("./runtime/nitro/image")
|
|
113
113
|
});
|
|
@@ -147,8 +147,9 @@ declare module 'nitropack' {
|
|
|
147
147
|
nitroConfig.virtual["#nuxt-og-image/constants"] = constScript;
|
|
148
148
|
nitroConfig.virtual["#nuxt-og-image/browser"] = `export { createBrowser } from '${runtimeDir}/browsers/${isEdge ? "lambda" : "default"}'`;
|
|
149
149
|
if (isEdge) {
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
["puppeteer", "bufferutil", "utf-8-validate"].forEach((name) => {
|
|
151
|
+
nitroConfig.alias[name] = "unenv/runtime/mock/proxy";
|
|
152
|
+
});
|
|
152
153
|
}
|
|
153
154
|
});
|
|
154
155
|
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
@@ -243,7 +244,7 @@ declare module 'nitropack' {
|
|
|
243
244
|
for (const entry of cleanupEntries) {
|
|
244
245
|
try {
|
|
245
246
|
const html = await readFile(entry.linkingHtml, "utf-8");
|
|
246
|
-
const newHtml = html.replace(new RegExp(`<link id="${LinkPrerenderId}" rel="prerender" href="(.*?)">`), "").replace(new RegExp(`<script id="${PayloadScriptId}" type="application/json">(.*?)<\/script>`), "").replace("\n\n", "\n");
|
|
247
|
+
const newHtml = html.replace("__OG_IMAGE_SCREENSHOT_ALT", `Web page screenshot of ${entry.route}.`).replace(new RegExp(`<link id="${LinkPrerenderId}" rel="prerender" href="(.*?)">`), "").replace(new RegExp(`<script id="${PayloadScriptId}" type="application/json">(.*?)<\/script>`), "").replace("\n\n", "\n");
|
|
247
248
|
if (html !== newHtml) {
|
|
248
249
|
await writeFile(entry.linkingHtml, newHtml, { encoding: "utf-8" });
|
|
249
250
|
}
|
|
@@ -2,28 +2,33 @@ import { useServerHead } from "@vueuse/head";
|
|
|
2
2
|
import { useRouter } from "#imports";
|
|
3
3
|
import { DefaultRuntimeImageSuffix, HtmlRendererRoute, LinkPrerenderId, MetaOgImageContentPlaceholder, PayloadScriptId } from "#nuxt-og-image/constants";
|
|
4
4
|
export function defineOgImageScreenshot() {
|
|
5
|
-
defineOgImage(
|
|
5
|
+
defineOgImage({
|
|
6
|
+
alt: "__OG_IMAGE_SCREENSHOT_ALT"
|
|
7
|
+
});
|
|
6
8
|
}
|
|
7
9
|
export function defineOgImage(options = {}) {
|
|
8
10
|
if (process.server) {
|
|
9
11
|
const router = useRouter();
|
|
10
12
|
const route = router?.currentRoute?.value?.path || "";
|
|
13
|
+
const meta = [
|
|
14
|
+
{
|
|
15
|
+
property: "twitter:card",
|
|
16
|
+
content: "summary_large_image"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
property: "og:image",
|
|
20
|
+
content: () => options.runtime ? `${route}/${DefaultRuntimeImageSuffix}` : MetaOgImageContentPlaceholder
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
if (options.alt) {
|
|
24
|
+
meta.push({
|
|
25
|
+
property: "og:image:alt",
|
|
26
|
+
content: options.alt
|
|
27
|
+
});
|
|
28
|
+
}
|
|
11
29
|
useServerHead({
|
|
12
|
-
meta
|
|
13
|
-
|
|
14
|
-
property: "twitter:card",
|
|
15
|
-
content: "summary_large_image"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
property: "og:image",
|
|
19
|
-
content: () => options.runtime ? `${route}/${DefaultRuntimeImageSuffix}` : MetaOgImageContentPlaceholder
|
|
20
|
-
},
|
|
21
|
-
options.alt ? {
|
|
22
|
-
property: "og:image:alt",
|
|
23
|
-
content: options.alt
|
|
24
|
-
} : {}
|
|
25
|
-
],
|
|
26
|
-
link: options.component ? [
|
|
30
|
+
meta,
|
|
31
|
+
link: !options.runtime && options.component ? [
|
|
27
32
|
{
|
|
28
33
|
id: LinkPrerenderId,
|
|
29
34
|
rel: "prerender",
|