nuxt-og-image 2.0.0-beta.59 → 2.0.0-beta.60
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 +51 -49
- package/dist/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/IconCSS.b41b9663.css +1 -0
- package/dist/client/_nuxt/{IconCSS.3ed6665a.js → IconCSS.c2e73ab2.js} +1 -1
- package/dist/client/_nuxt/{ImageLoader.98cdc4fb.js → ImageLoader.ed4bfccb.js} +1 -1
- package/dist/client/_nuxt/{entry.ddd5fc7b.css → entry.862302d7.css} +1 -1
- package/dist/client/_nuxt/{entry.725a580a.js → entry.f51ac6f7.js} +3 -3
- package/dist/client/_nuxt/{error-404.c6d590bd.js → error-404.a94c6c21.js} +1 -1
- package/dist/client/_nuxt/{error-500.05e72b5f.js → error-500.3955092a.js} +1 -1
- package/dist/client/_nuxt/{index.80d41946.js → index.17db8b1a.js} +1 -1
- package/dist/client/_nuxt/{options.334f5ba2.js → options.3e6c211b.js} +1 -1
- package/dist/client/_nuxt/{png.823fe00d.js → png.23a5e57c.js} +1 -1
- package/dist/client/_nuxt/{shiki.eefdab7f.js → shiki.2980d306.js} +1 -1
- package/dist/client/_nuxt/{svg.04e74616.js → svg.a8bba1f1.js} +1 -1
- package/dist/client/_nuxt/{vnodes.1f91e005.js → vnodes.64d635d6.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/options/index.html +2 -2
- package/dist/client/png/index.html +2 -2
- package/dist/client/svg/index.html +2 -2
- package/dist/client/vnodes/index.html +2 -2
- package/dist/module.d.ts +81 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +96 -32
- package/dist/runtime/components/{OgImageDynamic.d.ts → OgImage/Cached.d.ts} +1 -2
- package/dist/runtime/components/OgImage/Cached.mjs +10 -0
- package/dist/runtime/components/{OgImageScreenshot.d.ts → OgImage/Screenshot.d.ts} +1 -3
- package/dist/runtime/components/{OgImageScreenshot.mjs → OgImage/Screenshot.mjs} +2 -2
- package/dist/runtime/components/{OgImageStatic.d.ts → OgImage/WithoutCache.d.ts} +1 -2
- package/dist/runtime/components/OgImage/WithoutCache.mjs +10 -0
- package/dist/runtime/components/OgImage/_OgImageDynamic.d.ts +7 -0
- package/dist/runtime/components/{OgImageDynamic.mjs → OgImage/_OgImageDynamic.mjs} +3 -3
- package/dist/runtime/components/OgImage/_OgImageStatic.d.ts +7 -0
- package/dist/runtime/components/{OgImageStatic.mjs → OgImage/_OgImageStatic.mjs} +3 -3
- package/dist/runtime/components/OgImage/index.d.ts +4 -0
- package/dist/runtime/components/OgImage/index.mjs +9 -0
- package/dist/runtime/components/OgImageTemplate/Fallback.vue +155 -0
- package/dist/runtime/composables/defineOgImage.d.ts +12 -4
- package/dist/runtime/composables/defineOgImage.mjs +46 -23
- package/dist/runtime/nitro/middleware/og.png.mjs +9 -7
- package/dist/runtime/nitro/plugins/prerender.mjs +6 -4
- package/dist/runtime/nitro/routes/debug.d.ts +4 -0
- package/dist/runtime/nitro/routes/debug.mjs +6 -1
- package/dist/runtime/nitro/routes/html.mjs +5 -5
- package/dist/runtime/nitro/utils.d.ts +0 -1
- package/dist/runtime/nitro/utils.mjs +11 -10
- package/package.json +12 -10
- package/dist/client/_nuxt/IconCSS.8bbd2aa2.css +0 -1
- package/dist/runtime/components/OgImageBasic.island.vue +0 -97
- package/dist/runtime/nitro/util-hostname.d.ts +0 -2
- package/dist/runtime/nitro/util-hostname.mjs +0 -20
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { defineNuxtModule, useLogger, createResolver,
|
|
2
|
+
import { useNuxt, addTemplate, defineNuxtModule, useLogger, createResolver, installModule, addServerHandler, addImports, addComponent, addServerPlugin } from '@nuxt/kit';
|
|
3
3
|
import { execa } from 'execa';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import defu from 'defu';
|
|
@@ -10,6 +10,7 @@ import { tinyws } from 'tinyws';
|
|
|
10
10
|
import sirv from 'sirv';
|
|
11
11
|
import { pathExists, copy, mkdirp } from 'fs-extra';
|
|
12
12
|
import { globby } from 'globby';
|
|
13
|
+
import { updateSiteConfig, requireSiteConfig } from 'nuxt-site-config-kit';
|
|
13
14
|
import playwrightCore from 'playwright-core';
|
|
14
15
|
import { existsSync } from 'node:fs';
|
|
15
16
|
import { createBirpcGroup } from 'birpc';
|
|
@@ -316,6 +317,23 @@ function ensureDependencies(nuxt, dep) {
|
|
|
316
317
|
}));
|
|
317
318
|
}
|
|
318
319
|
|
|
320
|
+
function extendTypes(module, template) {
|
|
321
|
+
const nuxt = useNuxt();
|
|
322
|
+
addTemplate({
|
|
323
|
+
filename: `${module}.d.ts`,
|
|
324
|
+
getContents: () => {
|
|
325
|
+
const s = template();
|
|
326
|
+
return `// Generated by ${module}
|
|
327
|
+
${s}
|
|
328
|
+
export {}
|
|
329
|
+
`;
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
nuxt.hooks.hook("prepare:types", ({ references }) => {
|
|
333
|
+
references.push({ path: resolve(nuxt.options.buildDir, `${module}.d.ts`) });
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
319
337
|
const PATH = "/__nuxt_og_image__";
|
|
320
338
|
const PATH_ENTRY = `${PATH}/entry`;
|
|
321
339
|
const PATH_PLAYGROUND = `${PATH}/client`;
|
|
@@ -329,20 +347,21 @@ const module = defineNuxtModule({
|
|
|
329
347
|
configKey: "ogImage"
|
|
330
348
|
},
|
|
331
349
|
defaults(nuxt) {
|
|
332
|
-
const siteUrl = process.env.NUXT_PUBLIC_SITE_URL || process.env.NUXT_SITE_URL || nuxt.options.runtimeConfig.public?.siteUrl || nuxt.options.runtimeConfig.siteUrl;
|
|
333
350
|
return {
|
|
334
|
-
|
|
351
|
+
enabled: true,
|
|
335
352
|
defaults: {
|
|
336
|
-
component: "
|
|
353
|
+
component: "OgImageTemplateFallback",
|
|
337
354
|
width: 1200,
|
|
338
355
|
height: 630,
|
|
339
|
-
cacheTtl: 24 * 60 * 60 * 1e3
|
|
340
356
|
// default is to cache the image for 24 hours
|
|
357
|
+
cache: true,
|
|
358
|
+
cacheTtl: 24 * 60 * 60 * 1e3
|
|
341
359
|
},
|
|
360
|
+
componentDirs: ["OgImage", "OgImageTemplate"],
|
|
342
361
|
runtimeSatori: true,
|
|
343
362
|
runtimeBrowser: nuxt.options.dev,
|
|
344
363
|
fonts: [],
|
|
345
|
-
runtimeCacheStorage:
|
|
364
|
+
runtimeCacheStorage: true,
|
|
346
365
|
satoriOptions: {},
|
|
347
366
|
playground: process.env.NODE_ENV === "development" || nuxt.options.dev,
|
|
348
367
|
debug: false
|
|
@@ -350,8 +369,12 @@ const module = defineNuxtModule({
|
|
|
350
369
|
},
|
|
351
370
|
async setup(config, nuxt) {
|
|
352
371
|
const logger = useLogger("nuxt-og-image");
|
|
353
|
-
logger.level = config.debug ? 4 : 3;
|
|
354
|
-
|
|
372
|
+
logger.level = config.debug || nuxt.options.debug ? 4 : 3;
|
|
373
|
+
if (config.enabled === false) {
|
|
374
|
+
logger.debug("The module is disabled, skipping setup.");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const { resolve, resolvePath } = createResolver(import.meta.url);
|
|
355
378
|
logger.debug("Using Nitro preset", getNitroPreset(nuxt));
|
|
356
379
|
const nitroCompatibility = getNitroProviderCompatibility(nuxt);
|
|
357
380
|
logger.debug("Nitro compatibility", nitroCompatibility);
|
|
@@ -368,9 +391,14 @@ const module = defineNuxtModule({
|
|
|
368
391
|
logger.info(`\`nuxt-og-image\` is deploying to nitro target \`${nitroTarget}\` that installs extra dependencies.`);
|
|
369
392
|
await ensureDependencies(nuxt, ["puppeteer-core@14.1.1", "@sparticuz/chrome-aws-lambda@14.1.1"]);
|
|
370
393
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
394
|
+
await installModule(await resolvePath("nuxt-site-config"));
|
|
395
|
+
await updateSiteConfig({
|
|
396
|
+
_context: "nuxt-og-image:config",
|
|
397
|
+
url: config.siteUrl || config.host
|
|
398
|
+
});
|
|
399
|
+
requireSiteConfig("nuxt-og-image", {
|
|
400
|
+
url: "Required to generate absolute URLs for the og:image."
|
|
401
|
+
}, { prerender: true });
|
|
374
402
|
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
375
403
|
if (nuxt.options._generate) {
|
|
376
404
|
nuxt.options.nitro.storage["og-image"] = {
|
|
@@ -388,23 +416,14 @@ const module = defineNuxtModule({
|
|
|
388
416
|
return resolve(`../dist/${p}`);
|
|
389
417
|
};
|
|
390
418
|
nuxt.options.experimental.componentIslands = true;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
getContents: () => {
|
|
394
|
-
return `// Generated by nuxt-og-image
|
|
395
|
-
interface NuxtOgImageNitroRules {
|
|
419
|
+
extendTypes("nuxt-og-image", () => {
|
|
420
|
+
return `interface NuxtOgImageNitroRules {
|
|
396
421
|
ogImage?: false | Record<string, any>
|
|
397
422
|
}
|
|
398
423
|
declare module 'nitropack' {
|
|
399
424
|
interface NitroRouteRules extends NuxtOgImageNitroRules {}
|
|
400
425
|
interface NitroRouteConfig extends NuxtOgImageNitroRules {}
|
|
401
|
-
}
|
|
402
|
-
export {}
|
|
403
|
-
`;
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
nuxt.hooks.hook("prepare:types", ({ references }) => {
|
|
407
|
-
references.push({ path: resolve(nuxt.options.buildDir, "nuxt-og-image.d.ts") });
|
|
426
|
+
}`;
|
|
408
427
|
});
|
|
409
428
|
addServerHandler({
|
|
410
429
|
lazy: true,
|
|
@@ -446,7 +465,17 @@ export {}
|
|
|
446
465
|
});
|
|
447
466
|
}
|
|
448
467
|
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] = [];
|
|
449
|
-
[
|
|
468
|
+
[
|
|
469
|
+
// deprecated
|
|
470
|
+
"Dynamic",
|
|
471
|
+
"Static",
|
|
472
|
+
// new
|
|
473
|
+
"index",
|
|
474
|
+
"Cached",
|
|
475
|
+
"WithoutCache",
|
|
476
|
+
"Screenshot"
|
|
477
|
+
].forEach((name) => {
|
|
478
|
+
name = name === "index" ? "defineOgImage" : `defineOgImage${name}`;
|
|
450
479
|
addImports({
|
|
451
480
|
name,
|
|
452
481
|
from: resolve("./runtime/composables/defineOgImage")
|
|
@@ -454,16 +483,47 @@ export {}
|
|
|
454
483
|
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"].push(name);
|
|
455
484
|
});
|
|
456
485
|
await addComponent({
|
|
457
|
-
name: "
|
|
458
|
-
filePath: resolve("./runtime/components/
|
|
486
|
+
name: "OgImageTemplateFallback",
|
|
487
|
+
filePath: resolve("./runtime/components/OgImageTemplate/Fallback.vue"),
|
|
459
488
|
island: true
|
|
460
489
|
});
|
|
461
|
-
[
|
|
490
|
+
[
|
|
491
|
+
// deprecated
|
|
492
|
+
"Static",
|
|
493
|
+
"Dynamic",
|
|
494
|
+
// new
|
|
495
|
+
"index",
|
|
496
|
+
"Cached",
|
|
497
|
+
"WithoutCache",
|
|
498
|
+
"Screenshot"
|
|
499
|
+
].forEach((name) => {
|
|
462
500
|
addComponent({
|
|
463
|
-
name
|
|
464
|
-
filePath: resolve(`./runtime/components/${name}`)
|
|
501
|
+
name: name === "index" ? "OgImage" : `OgImage${name}`,
|
|
502
|
+
filePath: resolve(`./runtime/components/OgImage/${name}`)
|
|
465
503
|
});
|
|
466
504
|
});
|
|
505
|
+
const ogImageComponents = [];
|
|
506
|
+
nuxt.hook("components:extend", (components) => {
|
|
507
|
+
components.forEach((component) => {
|
|
508
|
+
let valid = false;
|
|
509
|
+
config.componentDirs.forEach((dir) => {
|
|
510
|
+
if (component.pascalName.startsWith(dir) || component.kebabName.startsWith(dir))
|
|
511
|
+
valid = true;
|
|
512
|
+
});
|
|
513
|
+
if (valid) {
|
|
514
|
+
component.island = true;
|
|
515
|
+
component.mode = "server";
|
|
516
|
+
ogImageComponents.push({ pascalName: component.pascalName, kebabName: component.kebabName });
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
addTemplate({
|
|
521
|
+
filename: "og-image-component-names.mjs",
|
|
522
|
+
getContents() {
|
|
523
|
+
return `export const componentNames = ${JSON.stringify(ogImageComponents)}`;
|
|
524
|
+
},
|
|
525
|
+
options: { mode: "server" }
|
|
526
|
+
});
|
|
467
527
|
const runtimeDir = resolve("./runtime");
|
|
468
528
|
nuxt.options.build.transpile.push(runtimeDir);
|
|
469
529
|
addServerPlugin(resolve("./runtime/nitro/plugins/prerender"));
|
|
@@ -484,9 +544,13 @@ export {}
|
|
|
484
544
|
nuxt.hooks.hook("modules:done", async () => {
|
|
485
545
|
nuxt.hooks.callHook("og-image:config", config);
|
|
486
546
|
nuxt.options.runtimeConfig["nuxt-og-image"] = {
|
|
487
|
-
|
|
547
|
+
satoriOptions: config.satoriOptions,
|
|
548
|
+
runtimeSatori: config.runtimeSatori,
|
|
549
|
+
runtimeBrowser: config.runtimeBrowser,
|
|
550
|
+
// @ts-expect-error runtime type
|
|
551
|
+
defaults: config.defaults,
|
|
488
552
|
// avoid adding credentials
|
|
489
|
-
runtimeCacheStorage:
|
|
553
|
+
runtimeCacheStorage: typeof config.runtimeCacheStorage === "boolean" ? "default" : config.runtimeCacheStorage.driver,
|
|
490
554
|
// convert the fonts to uniform type to fix ts issue
|
|
491
555
|
fonts: config.fonts.map((f) => {
|
|
492
556
|
if (typeof f === "string") {
|
|
@@ -631,7 +695,7 @@ export async function useProvider(provider) {
|
|
|
631
695
|
...extractedOptions,
|
|
632
696
|
...routeRules.ogImage || {}
|
|
633
697
|
};
|
|
634
|
-
if ((nuxt.options._generate || entry.
|
|
698
|
+
if ((nuxt.options._generate || entry.cache) && entry.provider === "browser")
|
|
635
699
|
screenshotQueue.push(entry);
|
|
636
700
|
});
|
|
637
701
|
if (nuxt.options.dev)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<OgImageOptions>>, {
|
|
1
|
+
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<any>, {} | {
|
|
3
2
|
[x: string]: any;
|
|
4
3
|
}, {}>;
|
|
5
4
|
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
|
+
import { defineOgImageCached } from "#imports";
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: "OgImageCached",
|
|
5
|
+
async setup(_, { attrs }) {
|
|
6
|
+
if (process.server)
|
|
7
|
+
await defineOgImageCached(attrs);
|
|
8
|
+
return () => null;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: import("vue").DefineComponent<OgImageScreenshotOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<OgImageScreenshotOptions>>, {
|
|
1
|
+
declare const _default: import("vue").DefineComponent<OgImageScreenshotOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<any>, {} | {
|
|
3
2
|
[x: string]: any;
|
|
4
|
-
[x: number]: any;
|
|
5
3
|
}, {}>;
|
|
6
4
|
export default _default;
|
|
@@ -2,9 +2,9 @@ import { defineComponent } from "vue";
|
|
|
2
2
|
import { defineOgImageScreenshot } from "#imports";
|
|
3
3
|
export default defineComponent({
|
|
4
4
|
name: "OgImageScreenshot",
|
|
5
|
-
setup(_, { attrs }) {
|
|
5
|
+
async setup(_, { attrs }) {
|
|
6
6
|
if (process.server)
|
|
7
|
-
defineOgImageScreenshot(attrs);
|
|
7
|
+
await defineOgImageScreenshot(attrs);
|
|
8
8
|
return () => null;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<OgImageOptions>>, {
|
|
1
|
+
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<any>, {} | {
|
|
3
2
|
[x: string]: any;
|
|
4
3
|
}, {}>;
|
|
5
4
|
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
|
+
import { defineOgImageWithoutCache } from "#imports";
|
|
3
|
+
export default defineComponent({
|
|
4
|
+
name: "OgImageWithoutCache",
|
|
5
|
+
async setup(_, { attrs }) {
|
|
6
|
+
if (process.server)
|
|
7
|
+
defineOgImageWithoutCache(attrs);
|
|
8
|
+
return () => null;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use OgImageWithoutCache
|
|
3
|
+
*/
|
|
4
|
+
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<any>, {} | {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
}, {}>;
|
|
7
|
+
export default _default;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineComponent } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { defineOgImageWithoutCache } from "#imports";
|
|
3
3
|
export default defineComponent({
|
|
4
4
|
name: "OgImageDynamic",
|
|
5
|
-
setup(_, { attrs }) {
|
|
5
|
+
async setup(_, { attrs }) {
|
|
6
6
|
if (process.server)
|
|
7
|
-
|
|
7
|
+
await defineOgImageWithoutCache(attrs);
|
|
8
8
|
return () => null;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use OgImageCached instead
|
|
3
|
+
*/
|
|
4
|
+
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<any>, {} | {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
}, {}>;
|
|
7
|
+
export default _default;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineComponent } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { defineOgImageCached } from "#imports";
|
|
3
3
|
export default defineComponent({
|
|
4
4
|
name: "OgImageStatic",
|
|
5
|
-
setup(_, { attrs }) {
|
|
5
|
+
async setup(_, { attrs }) {
|
|
6
6
|
if (process.server)
|
|
7
|
-
|
|
7
|
+
await defineOgImageCached(attrs);
|
|
8
8
|
return () => null;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<any>, {} | {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
}, {}>;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
// inherited attrs can mess up the satori parser
|
|
5
|
+
defineOptions({
|
|
6
|
+
inheritAttrs: false,
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
path: String,
|
|
11
|
+
title: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: 'Og Image Template',
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
type: String,
|
|
17
|
+
default: 'Set a description to change me.',
|
|
18
|
+
},
|
|
19
|
+
background: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: 'linear-gradient(to bottom, #dbf4ff, #fff1f1)',
|
|
22
|
+
},
|
|
23
|
+
color: {
|
|
24
|
+
type: String,
|
|
25
|
+
},
|
|
26
|
+
padding: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: '0 100px',
|
|
29
|
+
},
|
|
30
|
+
titleFontSize: {
|
|
31
|
+
type: String,
|
|
32
|
+
default: '75px',
|
|
33
|
+
},
|
|
34
|
+
descriptionFontSize: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: '35px',
|
|
37
|
+
},
|
|
38
|
+
icon: {
|
|
39
|
+
type: [String, Boolean],
|
|
40
|
+
default: false,
|
|
41
|
+
},
|
|
42
|
+
siteName: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: false,
|
|
45
|
+
},
|
|
46
|
+
siteLogo: {
|
|
47
|
+
type: String,
|
|
48
|
+
required: false,
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const backgroundAttrs = computed(() => {
|
|
53
|
+
// we want to make a
|
|
54
|
+
// const isBackgroundTw = props.background?.startsWith('bg-')
|
|
55
|
+
return {
|
|
56
|
+
style: {
|
|
57
|
+
display: 'flex',
|
|
58
|
+
position: 'absolute',
|
|
59
|
+
width: '100%',
|
|
60
|
+
height: '100%',
|
|
61
|
+
background: 'rgba(5, 5, 5,1)',
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const backgroundFlareAttrs = computed(() => {
|
|
67
|
+
// we want to make a
|
|
68
|
+
// const isBackgroundTw = props.background?.startsWith('bg-')
|
|
69
|
+
return {
|
|
70
|
+
style: {
|
|
71
|
+
display: 'flex',
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
right: '-100%',
|
|
74
|
+
top: '10%',
|
|
75
|
+
width: '200%',
|
|
76
|
+
height: '200%',
|
|
77
|
+
backgroundImage: 'radial-gradient(circle, rgba(0,220,130, 0.5) 0%, rgba(5, 5, 5,0.3) 50%, rgba(5, 5, 5,0) 70%)',
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const containerAttrs = computed(() => {
|
|
83
|
+
const isColorTw = props.color?.startsWith('text-')
|
|
84
|
+
|
|
85
|
+
const classes = [
|
|
86
|
+
'w-full',
|
|
87
|
+
'h-full',
|
|
88
|
+
'flex',
|
|
89
|
+
'text-gray-100',
|
|
90
|
+
'relative',
|
|
91
|
+
'items-center',
|
|
92
|
+
'justify-center',
|
|
93
|
+
]
|
|
94
|
+
const styles: Record<string, any> = {
|
|
95
|
+
padding: props.padding,
|
|
96
|
+
}
|
|
97
|
+
if (isColorTw)
|
|
98
|
+
classes.push(props.color)
|
|
99
|
+
else
|
|
100
|
+
styles.color = props.color
|
|
101
|
+
return { class: classes, style: styles }
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const titleAttrs = computed(() => {
|
|
105
|
+
const classes = []
|
|
106
|
+
const styles = {
|
|
107
|
+
fontWeight: 'bold',
|
|
108
|
+
marginBottom: '50px',
|
|
109
|
+
fontSize: props.titleFontSize,
|
|
110
|
+
}
|
|
111
|
+
return { class: classes, style: styles }
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const descriptionAttrs = computed(() => {
|
|
115
|
+
const classes = []
|
|
116
|
+
const styles = {
|
|
117
|
+
fontSize: props.descriptionFontSize,
|
|
118
|
+
}
|
|
119
|
+
return { class: classes, style: styles }
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const siteConfig = useSiteConfig()
|
|
123
|
+
const siteName = computed(() => {
|
|
124
|
+
return props.siteName || siteConfig.name
|
|
125
|
+
})
|
|
126
|
+
const siteLogo = computed(() => {
|
|
127
|
+
return props.siteLogo || siteConfig.logo || 'https://nuxt.com/assets/design-kit/logo/full-logo-green-light.png'
|
|
128
|
+
})
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<template>
|
|
132
|
+
<div v-bind="backgroundAttrs" />
|
|
133
|
+
<div v-bind="backgroundFlareAttrs" />
|
|
134
|
+
<div v-bind="containerAttrs">
|
|
135
|
+
<div class="flex flex-row justify-between items-center" style="margin-bottom: 100px;">
|
|
136
|
+
<div class="flex flex-col w-full" :style="icon ? { width: '65%' } : {}">
|
|
137
|
+
<div v-bind="titleAttrs">
|
|
138
|
+
{{ title || 'Null Title' }}
|
|
139
|
+
</div>
|
|
140
|
+
<div v-if="description" v-bind="descriptionAttrs">
|
|
141
|
+
{{ description }}
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
<div v-if="typeof icon === 'string'" style="width: 30%;" class="flex justify-end">
|
|
145
|
+
<Icon :name="icon" size="250px" style="margin: 0 auto;" />
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
<div class="flex flex-row absolute bottom-10 text-left items-start">
|
|
149
|
+
<img v-if="siteLogo" :src="siteLogo" height="30">
|
|
150
|
+
<div v-else-if="siteName" style="font-size: 25px;">
|
|
151
|
+
{{ siteName }}
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</template>
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { OgImageOptions, OgImageScreenshotOptions } from '../../types';
|
|
2
|
-
export declare function defineOgImageScreenshot(options?: OgImageScreenshotOptions): void
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare function defineOgImageScreenshot(options?: OgImageScreenshotOptions): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use `defineOgImage` or `defineOgImageCached` instead
|
|
5
|
+
*/
|
|
6
|
+
export declare function defineOgImageStatic(options?: OgImageOptions): Promise<void>;
|
|
7
|
+
export declare function defineOgImageCached(options?: OgImageOptions): Promise<void>;
|
|
8
|
+
export declare function defineOgImageWithoutCache(options?: OgImageOptions): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `defineOgImageWithoutCache` instead
|
|
11
|
+
*/
|
|
12
|
+
export declare function defineOgImageDynamic(options?: OgImageOptions): Promise<void>;
|
|
13
|
+
export declare function defineOgImage(_options?: OgImageOptions): Promise<void>;
|
|
@@ -1,45 +1,68 @@
|
|
|
1
1
|
import { withBase } from "ufo";
|
|
2
2
|
import { useRequestEvent } from "#app";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useNitroOrigin, useRouter, useRuntimeConfig, useServerHead, useSiteConfig } from "#imports";
|
|
4
|
+
import { componentNames } from "#build/og-image-component-names.mjs";
|
|
5
5
|
export function defineOgImageScreenshot(options = {}) {
|
|
6
6
|
const router = useRouter();
|
|
7
7
|
const route = router?.currentRoute?.value?.path || "";
|
|
8
|
-
defineOgImage({
|
|
8
|
+
return defineOgImage({
|
|
9
9
|
alt: `Web page screenshot${route ? ` of ${route}` : ""}.`,
|
|
10
10
|
provider: "browser",
|
|
11
11
|
component: null,
|
|
12
|
-
|
|
12
|
+
cache: true,
|
|
13
13
|
...options
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
export function defineOgImageStatic(options = {}) {
|
|
17
|
+
return defineOgImageCached(options);
|
|
18
|
+
}
|
|
19
|
+
export function defineOgImageCached(options = {}) {
|
|
20
|
+
const { defaults } = useRuntimeConfig()["nuxt-og-image"];
|
|
21
|
+
if (!defaults.cacheTtl && !options.cacheTtl)
|
|
22
|
+
options.cacheTtl = 60 * 60 * 24 * 7;
|
|
23
|
+
return defineOgImage({
|
|
24
|
+
cache: true,
|
|
22
25
|
...options
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
|
-
export function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
static: true,
|
|
28
|
+
export function defineOgImageWithoutCache(options = {}) {
|
|
29
|
+
return defineOgImage({
|
|
30
|
+
cache: false,
|
|
31
|
+
cacheTtl: 0,
|
|
30
32
|
...options
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
|
-
export function
|
|
35
|
+
export function defineOgImageDynamic(options = {}) {
|
|
36
|
+
return defineOgImageWithoutCache(options);
|
|
37
|
+
}
|
|
38
|
+
export async function defineOgImage(_options = {}) {
|
|
39
|
+
const options = { ...unref(_options) };
|
|
34
40
|
if (process.server) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
if (options.static)
|
|
42
|
+
options.cache = options.cache || options.static;
|
|
43
|
+
if (!options.provider)
|
|
44
|
+
options.provider = "satori";
|
|
45
|
+
const { defaults, runtimeSatori } = useRuntimeConfig()["nuxt-og-image"];
|
|
46
|
+
if (options.provider === "satori" && !runtimeSatori)
|
|
47
|
+
options.provider = "browser";
|
|
48
|
+
if (options.component && componentNames) {
|
|
49
|
+
const originalName = options.component;
|
|
50
|
+
let isValid = componentNames.some((component) => component.pascalName === originalName || component.kebabName === originalName);
|
|
51
|
+
if (!isValid) {
|
|
52
|
+
for (const component of componentNames) {
|
|
53
|
+
if (component.pascalName.endsWith(originalName) || component.kebabName.endsWith(originalName)) {
|
|
54
|
+
options.component = component.pascalName;
|
|
55
|
+
isValid = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
39
61
|
const router = useRouter();
|
|
40
62
|
const route = router?.currentRoute?.value?.path || "";
|
|
41
63
|
const e = useRequestEvent();
|
|
42
|
-
const baseUrl = process.env.prerender ?
|
|
64
|
+
const baseUrl = process.env.prerender ? (await useSiteConfig(e)).url : useNitroOrigin(e);
|
|
65
|
+
const src = withBase(`${route === "/" ? "" : route}/__og_image__/og.png`, baseUrl || "");
|
|
43
66
|
const meta = [
|
|
44
67
|
{
|
|
45
68
|
name: "twitter:card",
|
|
@@ -47,11 +70,11 @@ export function defineOgImage(options = {}) {
|
|
|
47
70
|
},
|
|
48
71
|
{
|
|
49
72
|
name: "twitter:image:src",
|
|
50
|
-
content:
|
|
73
|
+
content: src
|
|
51
74
|
},
|
|
52
75
|
{
|
|
53
76
|
property: "og:image",
|
|
54
|
-
content:
|
|
77
|
+
content: src
|
|
55
78
|
},
|
|
56
79
|
{
|
|
57
80
|
property: "og:image:width",
|