nuxt-og-image 0.4.7 → 0.5.0
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
CHANGED
|
@@ -18,7 +18,7 @@ Generate dynamic social share images for you Nuxt v3 app.
|
|
|
18
18
|
<tbody>
|
|
19
19
|
<td align="center">
|
|
20
20
|
<img width="800" height="0" /><br>
|
|
21
|
-
<i>Status:</i>
|
|
21
|
+
<i>Status:</i> Early Access</b> <br>
|
|
22
22
|
<sup> Please report any issues 🐛</sup><br>
|
|
23
23
|
<sub>Made possible by my <a href="https://github.com/sponsors/harlan-zw">Sponsor Program 💖</a><br> Follow me <a href="https://twitter.com/harlan_zw">@harlan_zw</a> 🐦 • Join <a href="https://discord.gg/275MBUBvgP">Discord</a> for help</sub><br>
|
|
24
24
|
<img width="800" height="0" />
|
|
@@ -29,32 +29,39 @@ Generate dynamic social share images for you Nuxt v3 app.
|
|
|
29
29
|
|
|
30
30
|
## Features
|
|
31
31
|
|
|
32
|
-
- 🧙
|
|
33
|
-
- 🎨
|
|
34
|
-
- 📸 OR just
|
|
35
|
-
- 📦
|
|
32
|
+
- 🧙 Pre-render `og:image`'s for your entire site in minutes with minimal config
|
|
33
|
+
- 🎨 Using a Vue component (powered by Nuxt Islands)
|
|
34
|
+
- 📸 OR just generate screenshots
|
|
35
|
+
- 📦 Choose your API: Composition or components
|
|
36
|
+
|
|
37
|
+
⚠️ SSR runtime rendering is experimental.
|
|
36
38
|
|
|
37
39
|
## Install
|
|
38
40
|
|
|
39
|
-
⚠️ This module is
|
|
41
|
+
⚠️ This module is in early access. Please report any issues you find.
|
|
40
42
|
|
|
41
43
|
```bash
|
|
44
|
+
# Install module
|
|
42
45
|
npm install --save-dev nuxt-og-image
|
|
43
46
|
# Using yarn
|
|
44
47
|
yarn add --dev nuxt-og-image
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
If you don't have a chromium binary installed on your system, run `npx playwright install`.
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
installed chrome.
|
|
52
|
+
### CI Build
|
|
51
53
|
|
|
52
|
-
If you
|
|
54
|
+
If you are using this module in a CI context and the images aren't being generated,
|
|
55
|
+
you should replace your build script with the following:
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
_package.json_
|
|
55
58
|
|
|
56
|
-
```
|
|
57
|
-
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "npx playwright install && nuxt build"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
58
65
|
```
|
|
59
66
|
|
|
60
67
|
## Setup
|
|
@@ -108,25 +115,6 @@ export default defineNuxtConfig({
|
|
|
108
115
|
})
|
|
109
116
|
```
|
|
110
117
|
|
|
111
|
-
### Recommended: Enable Nuxt Islands
|
|
112
|
-
|
|
113
|
-
To be able to preview the image in development and generate template images, you'll need
|
|
114
|
-
to enable Nuxt Islands.
|
|
115
|
-
|
|
116
|
-
If you're using Nuxt 3.0.0, you will need to switch to the [edge-release channel](https://nuxt.com/docs/guide/going-further/edge-channel#edge-release-channel).
|
|
117
|
-
|
|
118
|
-
Once that's done, you can enable the flag for islands.
|
|
119
|
-
|
|
120
|
-
_nuxt.config.ts_
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
export default defineNuxtConfig({
|
|
124
|
-
experimental: {
|
|
125
|
-
componentIslands: true
|
|
126
|
-
},
|
|
127
|
-
})
|
|
128
|
-
```
|
|
129
|
-
|
|
130
118
|
## Generating Screenshots
|
|
131
119
|
|
|
132
120
|
_Your page / app.vue / layout_
|
|
@@ -156,6 +144,7 @@ _Your page / app.vue / layout_
|
|
|
156
144
|
// Choose either Composition API
|
|
157
145
|
defineOgImage({
|
|
158
146
|
component: 'OgImageTemplate', // Nuxt Island component
|
|
147
|
+
alt: 'My awesome image', // alt text for image
|
|
159
148
|
// pass in any custom props
|
|
160
149
|
myCustomTitle: 'My Title'
|
|
161
150
|
})
|
|
@@ -168,6 +157,25 @@ defineOgImage({
|
|
|
168
157
|
</template>
|
|
169
158
|
```
|
|
170
159
|
|
|
160
|
+
### Requirements
|
|
161
|
+
|
|
162
|
+
To be able to preview the image in development and generate template images, you'll need
|
|
163
|
+
to enable Nuxt Islands.
|
|
164
|
+
|
|
165
|
+
If you're using Nuxt 3.0.0, you will need to switch to the [edge-release channel](https://nuxt.com/docs/guide/going-further/edge-channel#edge-release-channel).
|
|
166
|
+
|
|
167
|
+
Once that's done, you can enable the flag for islands.
|
|
168
|
+
|
|
169
|
+
_nuxt.config.ts_
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
export default defineNuxtConfig({
|
|
173
|
+
experimental: {
|
|
174
|
+
componentIslands: true
|
|
175
|
+
},
|
|
176
|
+
})
|
|
177
|
+
```
|
|
178
|
+
|
|
171
179
|
### Creating your own template
|
|
172
180
|
|
|
173
181
|
Create a new component with `.island.vue` as the suffix, such as `components/Banner.island.vue`.
|
|
@@ -250,6 +258,9 @@ The host of your site. This is required to generate the absolute path of the og:
|
|
|
250
258
|
Allows you to generate images at runtime in production. This uses a headless browser to generate images
|
|
251
259
|
and may have deployment issues.
|
|
252
260
|
|
|
261
|
+
⚠️ This is experimental and will likely not work in all environments.
|
|
262
|
+
|
|
263
|
+
|
|
253
264
|
## Examples
|
|
254
265
|
|
|
255
266
|
- [Unhead Docs](https://github.com/unjs/unhead/tree/main/docs)
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -9,6 +9,11 @@ import { withBase, joinURL } from 'ufo';
|
|
|
9
9
|
import fg from 'fast-glob';
|
|
10
10
|
import { join } from 'pathe';
|
|
11
11
|
|
|
12
|
+
const debugBinaryUsage = (s, error) => {
|
|
13
|
+
if (!process.dev) {
|
|
14
|
+
console.log(s, error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
12
17
|
async function createBrowser() {
|
|
13
18
|
try {
|
|
14
19
|
const playwrightCore = await import('playwright-core');
|
|
@@ -20,8 +25,7 @@ async function createBrowser() {
|
|
|
20
25
|
headless: awsChrome.headless
|
|
21
26
|
});
|
|
22
27
|
} catch (e) {
|
|
23
|
-
|
|
24
|
-
console.log("[nuxt-og-image] Skipping chrome-aws-lambda", e);
|
|
28
|
+
debugBinaryUsage("[nuxt-og-image] Skipping chrome-aws-lambda", e);
|
|
25
29
|
}
|
|
26
30
|
try {
|
|
27
31
|
const playwrightCore = await import('playwright-core');
|
|
@@ -32,8 +36,7 @@ async function createBrowser() {
|
|
|
32
36
|
executablePath: chromePath
|
|
33
37
|
});
|
|
34
38
|
} catch (e) {
|
|
35
|
-
|
|
36
|
-
console.log("[nuxt-og-image] Skipping chrome-launcher", e);
|
|
39
|
+
debugBinaryUsage("[nuxt-og-image] Skipping chrome-launcher", e);
|
|
37
40
|
}
|
|
38
41
|
try {
|
|
39
42
|
const playwright = await import(String("playwright"));
|
|
@@ -42,10 +45,9 @@ async function createBrowser() {
|
|
|
42
45
|
});
|
|
43
46
|
} catch (e) {
|
|
44
47
|
if (!process.dev)
|
|
45
|
-
|
|
48
|
+
debugBinaryUsage("[nuxt-og-image] Playwright failed", e);
|
|
46
49
|
throw new Error(`
|
|
47
|
-
Missing chromium binary.
|
|
48
|
-
Please run 'yarn add --dev playwright' or 'npm install --save-dev playwright'
|
|
50
|
+
Missing chromium binary. Please run "npx playwright install".
|
|
49
51
|
`);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
const debugBinaryUsage = (s, error) => {
|
|
2
|
+
if (!process.dev) {
|
|
3
|
+
console.log(s, error);
|
|
4
|
+
}
|
|
5
|
+
};
|
|
1
6
|
export async function createBrowser() {
|
|
2
7
|
try {
|
|
3
8
|
const playwrightCore = await import("playwright-core");
|
|
@@ -9,8 +14,7 @@ export async function createBrowser() {
|
|
|
9
14
|
headless: awsChrome.headless
|
|
10
15
|
});
|
|
11
16
|
} catch (e) {
|
|
12
|
-
|
|
13
|
-
console.log("[nuxt-og-image] Skipping chrome-aws-lambda", e);
|
|
17
|
+
debugBinaryUsage("[nuxt-og-image] Skipping chrome-aws-lambda", e);
|
|
14
18
|
}
|
|
15
19
|
try {
|
|
16
20
|
const playwrightCore = await import("playwright-core");
|
|
@@ -21,8 +25,7 @@ export async function createBrowser() {
|
|
|
21
25
|
executablePath: chromePath
|
|
22
26
|
});
|
|
23
27
|
} catch (e) {
|
|
24
|
-
|
|
25
|
-
console.log("[nuxt-og-image] Skipping chrome-launcher", e);
|
|
28
|
+
debugBinaryUsage("[nuxt-og-image] Skipping chrome-launcher", e);
|
|
26
29
|
}
|
|
27
30
|
try {
|
|
28
31
|
const playwright = await import(String("playwright"));
|
|
@@ -31,10 +34,9 @@ export async function createBrowser() {
|
|
|
31
34
|
});
|
|
32
35
|
} catch (e) {
|
|
33
36
|
if (!process.dev)
|
|
34
|
-
|
|
37
|
+
debugBinaryUsage("[nuxt-og-image] Playwright failed", e);
|
|
35
38
|
throw new Error(`
|
|
36
|
-
Missing chromium binary.
|
|
37
|
-
Please run 'yarn add --dev playwright' or 'npm install --save-dev playwright'
|
|
39
|
+
Missing chromium binary. Please run "npx playwright install".
|
|
38
40
|
`);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -10,10 +10,18 @@ export function defineOgImage(options = {}) {
|
|
|
10
10
|
const route = router?.currentRoute?.value?.path || "";
|
|
11
11
|
useServerHead({
|
|
12
12
|
meta: [
|
|
13
|
+
{
|
|
14
|
+
property: "twitter:card",
|
|
15
|
+
content: "summary_large_image"
|
|
16
|
+
},
|
|
13
17
|
{
|
|
14
18
|
property: "og:image",
|
|
15
19
|
content: () => options.runtime ? `${route}/${DefaultRuntimeImageSuffix}` : MetaOgImageContentPlaceholder
|
|
16
|
-
}
|
|
20
|
+
},
|
|
21
|
+
options.alt ? {
|
|
22
|
+
property: "og:image:alt",
|
|
23
|
+
content: options.alt
|
|
24
|
+
} : {}
|
|
17
25
|
],
|
|
18
26
|
link: options.component ? [
|
|
19
27
|
{
|