nuxt-og-image 0.5.3 → 0.5.5
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 +5 -3
- package/dist/runtime/composables/defineOgImage.mjs +21 -16
- package/package.json +2 -2
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
|
});
|
|
@@ -226,6 +226,8 @@ declare module 'nitropack' {
|
|
|
226
226
|
` ${Number(k) === entries.length - 1 ? "\u2514\u2500" : "\u251C\u2500"} /${config.outputDir}/${entry.fileName} (${generateTimeMS}ms) ${Math.round(Number(k) / (entries.length - 1) * 100)}%`
|
|
227
227
|
));
|
|
228
228
|
}
|
|
229
|
+
} else {
|
|
230
|
+
nitro.logger.log(chalk.red("Failed to create browser to create og:images."));
|
|
229
231
|
}
|
|
230
232
|
} catch (e) {
|
|
231
233
|
console.error(e);
|
|
@@ -244,7 +246,7 @@ declare module 'nitropack' {
|
|
|
244
246
|
for (const entry of cleanupEntries) {
|
|
245
247
|
try {
|
|
246
248
|
const html = await readFile(entry.linkingHtml, "utf-8");
|
|
247
|
-
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");
|
|
249
|
+
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");
|
|
248
250
|
if (html !== newHtml) {
|
|
249
251
|
await writeFile(entry.linkingHtml, newHtml, { encoding: "utf-8" });
|
|
250
252
|
}
|
|
@@ -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",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.5",
|
|
5
5
|
"packageManager": "pnpm@7.8.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@nuxt/kit": "3.0.0",
|
|
30
30
|
"chalk": "^5.2.0",
|
|
31
31
|
"chrome-launcher": "^0.15.1",
|
|
32
|
+
"playwright-core": "^1.28.1",
|
|
32
33
|
"defu": "^6.1.1",
|
|
33
34
|
"execa": "^6.1.0",
|
|
34
35
|
"fast-glob": "^3.2.12",
|
|
@@ -46,7 +47,6 @@
|
|
|
46
47
|
"bumpp": "^8.2.1",
|
|
47
48
|
"eslint": "8.29.0",
|
|
48
49
|
"nuxt": "npm:nuxt3@latest",
|
|
49
|
-
"playwright-core": "^1.28.1",
|
|
50
50
|
"puppeteer": "^19.4.0",
|
|
51
51
|
"vitest": "^0.25.5"
|
|
52
52
|
},
|