nuxt-og-image 5.0.4 → 5.1.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/dist/client/200.html +10 -10
- package/dist/client/404.html +10 -10
- package/dist/client/_nuxt/{DynFtWBP.js → BKhpHsoX.js} +1 -1
- package/dist/client/_nuxt/BLmTiKMJ.js +1 -0
- package/dist/client/_nuxt/{Ca79vr2h.js → DVcaHLff.js} +1 -1
- package/dist/client/_nuxt/DpHmQ6sx.js +3991 -0
- package/dist/client/_nuxt/Dy0dDCjl.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/a1854235-e297-4e1d-9aec-f8c2f24f15ac.json +1 -0
- package/dist/client/_nuxt/entry.Dw_RMJvc.css +1 -0
- package/dist/client/_nuxt/error-404.Db0f7OxX.css +1 -0
- package/dist/client/_nuxt/error-500.CgBP5IsV.css +1 -0
- package/dist/client/index.html +10 -10
- package/dist/module.cjs +211 -143
- package/dist/module.d.cts +1 -1
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +213 -145
- package/dist/runtime/app/composables/mock.js +14 -0
- package/dist/runtime/app/utils/plugins.js +2 -0
- package/dist/runtime/server/og-image/context.js +19 -9
- package/dist/runtime/server/og-image/satori/plugins/nuxt-icon.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/nuxt-icon.js +20 -0
- package/dist/runtime/server/og-image/satori/transforms/inlineCss.js +1 -1
- package/dist/runtime/server/og-image/satori/vnodes.js +3 -1
- package/dist/runtime/server/util/encoding.js +2 -2
- package/dist/runtime/types.d.ts +1 -0
- package/package.json +20 -20
- package/virtual.d.ts +2 -2
- package/dist/client/_nuxt/DGRTSKzu.js +0 -1
- package/dist/client/_nuxt/DRTpreTA.js +0 -3979
- package/dist/client/_nuxt/DTAJTTim.js +0 -1
- package/dist/client/_nuxt/builds/meta/f2f318ac-acd5-43ce-b2d4-31208c9cc147.json +0 -1
- package/dist/client/_nuxt/entry.DPIkPTtM.css +0 -1
- package/dist/client/_nuxt/error-404.D1BP3bDE.css +0 -1
- package/dist/client/_nuxt/error-500.28Afz2Fq.css +0 -1
package/dist/module.cjs
CHANGED
|
@@ -206,10 +206,11 @@ async function applyNitroPresetCompatibility(nitroConfig, options) {
|
|
|
206
206
|
const { resolve } = options;
|
|
207
207
|
const satoriEnabled = typeof options.compatibility?.satori !== "undefined" ? !!options.compatibility.satori : !!compatibility.satori;
|
|
208
208
|
const chromiumEnabled = typeof options.compatibility?.chromium !== "undefined" ? !!options.compatibility.chromium : !!compatibility.chromium;
|
|
209
|
-
|
|
210
|
-
nitroConfig.alias["#og-image/renderers/
|
|
209
|
+
const emptyMock = await resolve.resolvePath("./runtime/mock/empty");
|
|
210
|
+
nitroConfig.alias["#og-image/renderers/satori"] = satoriEnabled ? await resolve.resolvePath("./runtime/server/og-image/satori/renderer") : emptyMock;
|
|
211
|
+
nitroConfig.alias["#og-image/renderers/chromium"] = chromiumEnabled ? await resolve.resolvePath("./runtime/server/og-image/chromium/renderer") : emptyMock;
|
|
211
212
|
const resolvedCompatibility = {};
|
|
212
|
-
function applyBinding(key) {
|
|
213
|
+
async function applyBinding(key) {
|
|
213
214
|
let binding = options.compatibility?.[key];
|
|
214
215
|
if (typeof binding === "undefined")
|
|
215
216
|
binding = compatibility[key];
|
|
@@ -222,15 +223,15 @@ async function applyNitroPresetCompatibility(nitroConfig, options) {
|
|
|
222
223
|
}
|
|
223
224
|
resolvedCompatibility[key] = binding;
|
|
224
225
|
return {
|
|
225
|
-
[`#og-image/bindings/${key}`]: binding === false ?
|
|
226
|
+
[`#og-image/bindings/${key}`]: binding === false ? emptyMock : await resolve.resolvePath(`./runtime/server/og-image/bindings/${key}/${binding}`)
|
|
226
227
|
};
|
|
227
228
|
}
|
|
228
229
|
nitroConfig.alias = defu.defu(
|
|
229
|
-
applyBinding("chromium"),
|
|
230
|
-
applyBinding("satori"),
|
|
231
|
-
applyBinding("resvg"),
|
|
232
|
-
applyBinding("sharp"),
|
|
233
|
-
applyBinding("css-inline"),
|
|
230
|
+
await applyBinding("chromium"),
|
|
231
|
+
await applyBinding("satori"),
|
|
232
|
+
await applyBinding("resvg"),
|
|
233
|
+
await applyBinding("sharp"),
|
|
234
|
+
await applyBinding("css-inline"),
|
|
234
235
|
nitroConfig.alias || {}
|
|
235
236
|
);
|
|
236
237
|
if (Object.values(compatibility).includes("wasm")) {
|
|
@@ -264,11 +265,11 @@ async function setupBuildHandler(config, resolve, nuxt = kit.useNuxt()) {
|
|
|
264
265
|
nuxt.options.nitro.storage["og-image"] = config.runtimeCacheStorage;
|
|
265
266
|
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
266
267
|
await applyNitroPresetCompatibility(nitroConfig, { compatibility: config.compatibility?.runtime, resolve });
|
|
267
|
-
nitroConfig.alias.electron = resolve("./runtime/mock/proxy-cjs");
|
|
268
|
-
nitroConfig.alias.bufferutil = resolve("./runtime/mock/proxy-cjs");
|
|
269
|
-
nitroConfig.alias["utf-8-validate"] = resolve("./runtime/mock/proxy-cjs");
|
|
270
|
-
nitroConfig.alias.queue = resolve("./runtime/mock/proxy-cjs");
|
|
271
|
-
nitroConfig.alias["chromium-bidi"] = resolve("./runtime/mock/proxy-cjs");
|
|
268
|
+
nitroConfig.alias.electron = await resolve.resolvePath("./runtime/mock/proxy-cjs");
|
|
269
|
+
nitroConfig.alias.bufferutil = await resolve.resolvePath("./runtime/mock/proxy-cjs");
|
|
270
|
+
nitroConfig.alias["utf-8-validate"] = await resolve.resolvePath("./runtime/mock/proxy-cjs");
|
|
271
|
+
nitroConfig.alias.queue = await resolve.resolvePath("./runtime/mock/proxy-cjs");
|
|
272
|
+
nitroConfig.alias["chromium-bidi"] = await resolve.resolvePath("./runtime/mock/proxy-cjs");
|
|
272
273
|
});
|
|
273
274
|
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
274
275
|
const target = resolveNitroPreset(nitro.options);
|
|
@@ -345,8 +346,27 @@ function setupDevToolsUI(options, resolve, nuxt = kit.useNuxt()) {
|
|
|
345
346
|
};
|
|
346
347
|
});
|
|
347
348
|
}
|
|
349
|
+
const useNitro = new Promise((resolve2) => {
|
|
350
|
+
nuxt.hooks.hook("nitro:init", resolve2);
|
|
351
|
+
});
|
|
348
352
|
devtoolsKit.onDevToolsInitialized(async () => {
|
|
349
|
-
const rpc = devtoolsKit.extendServerRpc("nuxt-og-image", {
|
|
353
|
+
const rpc = devtoolsKit.extendServerRpc("nuxt-og-image", {
|
|
354
|
+
async ejectCommunityTemplate(path) {
|
|
355
|
+
const [dirName, componentName] = path.split("/");
|
|
356
|
+
const dir = resolve(nuxt.options.rootDir, "components", dirName);
|
|
357
|
+
if (!fs.existsSync(dir)) {
|
|
358
|
+
fs.mkdirSync(dir);
|
|
359
|
+
}
|
|
360
|
+
const newPath = resolve(dir, componentName);
|
|
361
|
+
const templatePath = resolve(`./runtime/app/components/Templates/Community/${componentName}`);
|
|
362
|
+
const template = (await promises.readFile(templatePath, "utf-8")).replace("{{ title }}", `{{ title }} - Ejected!`);
|
|
363
|
+
await promises.writeFile(newPath, template, { encoding: "utf-8" });
|
|
364
|
+
await kit.updateTemplates({ filter: (t) => t.filename.includes("nuxt-og-image/components.mjs") });
|
|
365
|
+
const nitro = await useNitro;
|
|
366
|
+
await nitro.hooks.callHook("rollup:reload");
|
|
367
|
+
return newPath;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
350
370
|
nuxt.hook("builder:watch", (e, path) => {
|
|
351
371
|
path = node_path.relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, path));
|
|
352
372
|
if ((e === "change" || e.includes("link")) && (path.startsWith("pages") || path.startsWith("content"))) {
|
|
@@ -546,6 +566,10 @@ function normaliseFontInput(fonts) {
|
|
|
546
566
|
});
|
|
547
567
|
}
|
|
548
568
|
|
|
569
|
+
function isProviderEnabledForEnv(provider, nuxt, config) {
|
|
570
|
+
return nuxt.options.dev && config.compatibility?.dev?.[provider] !== false || !nuxt.options.dev && (config.compatibility?.runtime?.[provider] !== false || config.compatibility?.prerender?.[provider] !== false);
|
|
571
|
+
}
|
|
572
|
+
const defaultComponentDirs = ["OgImage", "og-image", "OgImageTemplate"];
|
|
549
573
|
const module$1 = kit.defineNuxtModule({
|
|
550
574
|
meta: {
|
|
551
575
|
name: "nuxt-og-image",
|
|
@@ -568,14 +592,15 @@ const module$1 = kit.defineNuxtModule({
|
|
|
568
592
|
// default is to cache the image for 3 day (72 hours)
|
|
569
593
|
cacheMaxAgeSeconds: 60 * 60 * 24 * 3
|
|
570
594
|
},
|
|
571
|
-
componentDirs:
|
|
595
|
+
componentDirs: defaultComponentDirs,
|
|
572
596
|
fonts: [],
|
|
573
597
|
runtimeCacheStorage: true,
|
|
574
598
|
debug: stdEnv.isDevelopment
|
|
575
599
|
};
|
|
576
600
|
},
|
|
577
601
|
async setup(config, nuxt) {
|
|
578
|
-
const
|
|
602
|
+
const resolver = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
|
|
603
|
+
const { resolve } = resolver;
|
|
579
604
|
const { version } = await pkgTypes.readPackageJSON(resolve("../package.json"));
|
|
580
605
|
logger_js.logger.level = config.debug || nuxt.options.debug ? 4 : 3;
|
|
581
606
|
if (config.enabled === false) {
|
|
@@ -607,68 +632,152 @@ const module$1 = kit.defineNuxtModule({
|
|
|
607
632
|
nuxt.options.alias["#og-image-cache"] = resolve("./runtime/server/og-image/cache/mock");
|
|
608
633
|
}
|
|
609
634
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
635
|
+
const basePath = config.zeroRuntime ? "./runtime/server/routes/__zero-runtime" : "./runtime/server/routes";
|
|
636
|
+
let publicDirAbs = nuxt.options.dir.public;
|
|
637
|
+
if (!pathe.isAbsolute(publicDirAbs)) {
|
|
638
|
+
publicDirAbs = publicDirAbs in nuxt.options.alias ? nuxt.options.alias[publicDirAbs] : resolve(nuxt.options.rootDir, publicDirAbs);
|
|
639
|
+
}
|
|
640
|
+
if (isProviderEnabledForEnv("satori", nuxt, config)) {
|
|
641
|
+
let isUsingSharp = false;
|
|
642
|
+
if (isProviderEnabledForEnv("sharp", nuxt, config)) {
|
|
643
|
+
const userConfiguredExtension = config.defaults.extension;
|
|
644
|
+
const hasConfiguredJpegs = userConfiguredExtension && ["jpeg", "jpg"].includes(userConfiguredExtension);
|
|
645
|
+
if (!!config.sharpOptions || hasConfiguredJpegs && config.defaults.renderer !== "chromium") {
|
|
646
|
+
isUsingSharp = true;
|
|
647
|
+
const hasSharpDependency = await hasResolvableDependency("sharp");
|
|
648
|
+
if (hasSharpDependency && !targetCompatibility.sharp) {
|
|
649
|
+
logger_js.logger.warn(`Rendering JPEGs requires sharp which does not work with ${preset}. Images will be rendered as PNG at runtime.`);
|
|
650
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
651
|
+
runtime: { sharp: false }
|
|
652
|
+
});
|
|
653
|
+
} else if (!hasSharpDependency) {
|
|
654
|
+
logger_js.logger.warn("You have enabled `JPEG` images. These require the `sharp` dependency which is missing, installing it for you.");
|
|
655
|
+
await ensureDependencies(["sharp"]);
|
|
656
|
+
logger_js.logger.warn("Support for `sharp` is limited so check the compatibility guide.");
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (!isUsingSharp) {
|
|
618
661
|
config.compatibility = defu.defu(config.compatibility, {
|
|
619
|
-
runtime: { sharp: false }
|
|
662
|
+
runtime: { sharp: false },
|
|
663
|
+
dev: { sharp: false },
|
|
664
|
+
prerender: { sharp: false }
|
|
620
665
|
});
|
|
621
|
-
} else if (!hasSharpDependency) {
|
|
622
|
-
logger_js.logger.warn("You have enabled `JPEG` images. These require the `sharp` dependency which is missing, installing it for you.");
|
|
623
|
-
await ensureDependencies(["sharp"]);
|
|
624
|
-
logger_js.logger.warn("Support for `sharp` is limited so check the compatibility guide.");
|
|
625
666
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
667
|
+
if (isProviderEnabledForEnv("resvg", nuxt, config)) {
|
|
668
|
+
await import('@resvg/resvg-js').catch(() => {
|
|
669
|
+
logger_js.logger.warn("ReSVG is missing dependencies for environment. Falling back to WASM version, this may slow down PNG rendering.");
|
|
670
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
671
|
+
dev: { resvg: "wasm-fs" },
|
|
672
|
+
prerender: { resvg: "wasm-fs" }
|
|
673
|
+
});
|
|
674
|
+
if (targetCompatibility.resvg === "node") {
|
|
675
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
676
|
+
runtime: { resvg: "wasm" }
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
if (!config.fonts.length) {
|
|
682
|
+
config.fonts = [
|
|
683
|
+
{
|
|
684
|
+
name: "Inter",
|
|
685
|
+
weight: 400,
|
|
686
|
+
path: resolve("./runtime/assets/Inter-normal-400.ttf.base64"),
|
|
687
|
+
absolutePath: true
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
name: "Inter",
|
|
691
|
+
weight: 700,
|
|
692
|
+
path: resolve("./runtime/assets/Inter-normal-700.ttf.base64"),
|
|
693
|
+
absolutePath: true
|
|
694
|
+
}
|
|
695
|
+
];
|
|
696
|
+
}
|
|
697
|
+
const serverFontsDir = resolve(nuxt.options.buildDir, "cache", `nuxt-og-image@${version}`, "_fonts");
|
|
698
|
+
const fontStorage = unstorage.createStorage({
|
|
699
|
+
driver: fsDriver__default({
|
|
700
|
+
base: serverFontsDir
|
|
701
|
+
})
|
|
702
|
+
});
|
|
703
|
+
config.fonts = (await Promise.all(normaliseFontInput(config.fonts).map(async (f) => {
|
|
704
|
+
const fontKey = `${f.name}:${f.style}:${f.weight}`;
|
|
705
|
+
const fontFileBase = fontKey.replaceAll(":", "-");
|
|
706
|
+
if (!f.key && !f.path) {
|
|
707
|
+
if (preset === "stackblitz") {
|
|
708
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because remote fonts are not available in StackBlitz, please use a local font.`);
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
if (await downloadFont(f, fontStorage, config.googleFontMirror)) {
|
|
712
|
+
f.key = `nuxt-og-image:fonts:${fontFileBase}.ttf.base64`;
|
|
713
|
+
} else {
|
|
714
|
+
logger_js.logger.warn(`Failed to download font ${fontKey}. You may be offline or behind a firewall blocking Google. Consider setting \`googleFontMirror: true\`.`);
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
} else if (f.path) {
|
|
718
|
+
const extension = pathe.basename(f.path.replace(".base64", "")).split(".").pop();
|
|
719
|
+
if (!["woff", "ttf", "otf"].includes(extension)) {
|
|
720
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because the file extension ${extension} is not supported. Only woff, ttf and otf are supported.`);
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
if (!f.absolutePath)
|
|
724
|
+
f.path = resolve(publicDirAbs, ufo.withoutLeadingSlash(f.path));
|
|
725
|
+
if (!fs.existsSync(f.path)) {
|
|
726
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because the file does not exist at path ${f.path}.`);
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
const fontData = await promises.readFile(f.path, f.path.endsWith(".base64") ? "utf-8" : "base64");
|
|
730
|
+
f.key = `nuxt-og-image:fonts:${fontFileBase}.${extension}.base64`;
|
|
731
|
+
await fontStorage.setItem(`${fontFileBase}.${extension}.base64`, fontData);
|
|
732
|
+
delete f.path;
|
|
733
|
+
delete f.absolutePath;
|
|
734
|
+
}
|
|
735
|
+
return f;
|
|
736
|
+
}))).filter(Boolean);
|
|
737
|
+
const fontKeys = config.fonts.map((f) => f.key?.split(":").pop());
|
|
738
|
+
const fontStorageKeys = await fontStorage.getKeys();
|
|
739
|
+
await Promise.all(fontStorageKeys.filter((key) => !fontKeys.includes(key)).map(async (key) => {
|
|
740
|
+
logger_js.logger.info(`Nuxt OG Image removing outdated cached font file \`${key}\``);
|
|
741
|
+
await fontStorage.removeItem(key);
|
|
742
|
+
}));
|
|
743
|
+
if (!config.zeroRuntime) {
|
|
744
|
+
nuxt.options.nitro.serverAssets = nuxt.options.nitro.serverAssets || [];
|
|
745
|
+
nuxt.options.nitro.serverAssets.push({ baseName: "nuxt-og-image:fonts", dir: serverFontsDir });
|
|
746
|
+
}
|
|
747
|
+
kit.addServerHandler({
|
|
748
|
+
lazy: true,
|
|
749
|
+
route: "/__og-image__/font/**",
|
|
750
|
+
handler: resolve(`${basePath}/font`)
|
|
632
751
|
});
|
|
633
752
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
runtime: { chromium: chromiumBinding.runtime },
|
|
657
|
-
dev: { chromium: chromiumBinding.dev },
|
|
658
|
-
prerender: { chromium: chromiumBinding.prerender }
|
|
659
|
-
});
|
|
660
|
-
await import('@resvg/resvg-js').catch(() => {
|
|
661
|
-
logger_js.logger.warn("ReSVG is missing dependencies for environment. Falling back to WASM version, this may slow down PNG rendering.");
|
|
753
|
+
if (isProviderEnabledForEnv("chromium", nuxt, config)) {
|
|
754
|
+
const hasChromeLocally = checkLocalChrome();
|
|
755
|
+
const hasPlaywrightDependency = await hasResolvableDependency("playwright");
|
|
756
|
+
const chromeCompatibilityFlags = {
|
|
757
|
+
prerender: config.compatibility?.prerender?.chromium,
|
|
758
|
+
dev: config.compatibility?.dev?.chromium,
|
|
759
|
+
runtime: config.compatibility?.runtime?.chromium
|
|
760
|
+
};
|
|
761
|
+
const chromiumBinding = {
|
|
762
|
+
dev: null,
|
|
763
|
+
prerender: null,
|
|
764
|
+
runtime: null
|
|
765
|
+
};
|
|
766
|
+
if (nuxt.options.dev) {
|
|
767
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.dev))
|
|
768
|
+
chromiumBinding.dev = hasChromeLocally ? "chrome-launcher" : hasPlaywrightDependency ? "playwright" : "on-demand";
|
|
769
|
+
} else {
|
|
770
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.prerender))
|
|
771
|
+
chromiumBinding.prerender = hasChromeLocally ? "chrome-launcher" : hasPlaywrightDependency ? "playwright" : "on-demand";
|
|
772
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.runtime))
|
|
773
|
+
chromiumBinding.runtime = hasPlaywrightDependency ? "playwright" : null;
|
|
774
|
+
}
|
|
662
775
|
config.compatibility = defu.defu(config.compatibility, {
|
|
663
|
-
|
|
664
|
-
|
|
776
|
+
runtime: { chromium: chromiumBinding.runtime },
|
|
777
|
+
dev: { chromium: chromiumBinding.dev },
|
|
778
|
+
prerender: { chromium: chromiumBinding.prerender }
|
|
665
779
|
});
|
|
666
|
-
|
|
667
|
-
config.compatibility = defu.defu(config.compatibility, {
|
|
668
|
-
runtime: { resvg: "wasm" }
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
});
|
|
780
|
+
}
|
|
672
781
|
await kit$1.installNuxtSiteConfig();
|
|
673
782
|
const usingNuxtContent = kit.hasNuxtModule("@nuxt/content");
|
|
674
783
|
const isNuxtContentV3 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^3");
|
|
@@ -680,73 +789,7 @@ const module$1 = kit.defineNuxtModule({
|
|
|
680
789
|
} else if (isNuxtContentV2) {
|
|
681
790
|
kit.addServerPlugin(resolve("./runtime/server/plugins/nuxt-content-v2"));
|
|
682
791
|
}
|
|
683
|
-
if (!config.fonts.length) {
|
|
684
|
-
config.fonts = [
|
|
685
|
-
{ name: "Inter", weight: 400, path: resolve("./runtime/assets/Inter-normal-400.ttf.base64"), absolutePath: true },
|
|
686
|
-
{ name: "Inter", weight: 700, path: resolve("./runtime/assets/Inter-normal-700.ttf.base64"), absolutePath: true }
|
|
687
|
-
];
|
|
688
|
-
}
|
|
689
|
-
let publicDirAbs = nuxt.options.dir.public;
|
|
690
|
-
if (!pathe.isAbsolute(publicDirAbs)) {
|
|
691
|
-
publicDirAbs = publicDirAbs in nuxt.options.alias ? nuxt.options.alias[publicDirAbs] : resolve(nuxt.options.rootDir, publicDirAbs);
|
|
692
|
-
}
|
|
693
|
-
const serverFontsDir = resolve(nuxt.options.buildDir, "cache", `nuxt-og-image@${version}`, "_fonts");
|
|
694
|
-
const fontStorage = unstorage.createStorage({
|
|
695
|
-
driver: fsDriver__default({
|
|
696
|
-
base: serverFontsDir
|
|
697
|
-
})
|
|
698
|
-
});
|
|
699
|
-
config.fonts = (await Promise.all(normaliseFontInput(config.fonts).map(async (f) => {
|
|
700
|
-
const fontKey = `${f.name}:${f.style}:${f.weight}`;
|
|
701
|
-
const fontFileBase = fontKey.replaceAll(":", "-");
|
|
702
|
-
if (!f.key && !f.path) {
|
|
703
|
-
if (preset === "stackblitz") {
|
|
704
|
-
logger_js.logger.warn(`The ${fontKey} font was skipped because remote fonts are not available in StackBlitz, please use a local font.`);
|
|
705
|
-
return false;
|
|
706
|
-
}
|
|
707
|
-
if (await downloadFont(f, fontStorage, config.googleFontMirror)) {
|
|
708
|
-
f.key = `nuxt-og-image:fonts:${fontFileBase}.ttf.base64`;
|
|
709
|
-
} else {
|
|
710
|
-
logger_js.logger.warn(`Failed to download font ${fontKey}. You may be offline or behind a firewall blocking Google. Consider setting \`googleFontMirror: true\`.`);
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
} else if (f.path) {
|
|
714
|
-
const extension = pathe.basename(f.path.replace(".base64", "")).split(".").pop();
|
|
715
|
-
if (!["woff", "ttf", "otf"].includes(extension)) {
|
|
716
|
-
logger_js.logger.warn(`The ${fontKey} font was skipped because the file extension ${extension} is not supported. Only woff, ttf and otf are supported.`);
|
|
717
|
-
return false;
|
|
718
|
-
}
|
|
719
|
-
if (!f.absolutePath)
|
|
720
|
-
f.path = resolve(publicDirAbs, ufo.withoutLeadingSlash(f.path));
|
|
721
|
-
if (!fs.existsSync(f.path)) {
|
|
722
|
-
logger_js.logger.warn(`The ${fontKey} font was skipped because the file does not exist at path ${f.path}.`);
|
|
723
|
-
return false;
|
|
724
|
-
}
|
|
725
|
-
const fontData = await promises.readFile(f.path, f.path.endsWith(".base64") ? "utf-8" : "base64");
|
|
726
|
-
f.key = `nuxt-og-image:fonts:${fontFileBase}.${extension}.base64`;
|
|
727
|
-
await fontStorage.setItem(`${fontFileBase}.${extension}.base64`, fontData);
|
|
728
|
-
delete f.path;
|
|
729
|
-
delete f.absolutePath;
|
|
730
|
-
}
|
|
731
|
-
return f;
|
|
732
|
-
}))).filter(Boolean);
|
|
733
|
-
const fontKeys = config.fonts.map((f) => f.key?.split(":").pop());
|
|
734
|
-
const fontStorageKeys = await fontStorage.getKeys();
|
|
735
|
-
await Promise.all(fontStorageKeys.filter((key) => !fontKeys.includes(key)).map(async (key) => {
|
|
736
|
-
logger_js.logger.info(`Nuxt OG Image removing outdated cached font file \`${key}\``);
|
|
737
|
-
await fontStorage.removeItem(key);
|
|
738
|
-
}));
|
|
739
|
-
if (!config.zeroRuntime) {
|
|
740
|
-
nuxt.options.nitro.serverAssets = nuxt.options.nitro.serverAssets || [];
|
|
741
|
-
nuxt.options.nitro.serverAssets.push({ baseName: "nuxt-og-image:fonts", dir: serverFontsDir });
|
|
742
|
-
}
|
|
743
792
|
nuxt.options.experimental.componentIslands ||= true;
|
|
744
|
-
const basePath = config.zeroRuntime ? "./runtime/server/routes/__zero-runtime" : "./runtime/server/routes";
|
|
745
|
-
kit.addServerHandler({
|
|
746
|
-
lazy: true,
|
|
747
|
-
route: "/__og-image__/font/**",
|
|
748
|
-
handler: resolve(`${basePath}/font`)
|
|
749
|
-
});
|
|
750
793
|
if (config.debug || nuxt.options.dev) {
|
|
751
794
|
kit.addServerHandler({
|
|
752
795
|
lazy: true,
|
|
@@ -767,7 +810,18 @@ const module$1 = kit.defineNuxtModule({
|
|
|
767
810
|
if (!nuxt.options.dev) {
|
|
768
811
|
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] = [];
|
|
769
812
|
}
|
|
770
|
-
[
|
|
813
|
+
[
|
|
814
|
+
"defineOgImage",
|
|
815
|
+
"defineOgImageComponent",
|
|
816
|
+
{ name: "defineOgImageScreenshot", enabled: isProviderEnabledForEnv("chromium", nuxt, config) }
|
|
817
|
+
].forEach((name) => {
|
|
818
|
+
if (typeof name === "object") {
|
|
819
|
+
if (!name.enabled) {
|
|
820
|
+
kit.addImports({ name: name.name, from: resolve(`./runtime/app/composables/mock`) });
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
name = name.name;
|
|
824
|
+
}
|
|
771
825
|
kit.addImports({
|
|
772
826
|
name,
|
|
773
827
|
from: resolve(`./runtime/app/composables/${name}`)
|
|
@@ -797,6 +851,17 @@ const module$1 = kit.defineNuxtModule({
|
|
|
797
851
|
const basePluginPath = `./runtime/app/plugins${config.zeroRuntime ? "/__zero-runtime" : ""}`;
|
|
798
852
|
kit.addPlugin({ mode: "server", src: resolve(`${basePluginPath}/route-rule-og-image.server`) });
|
|
799
853
|
kit.addPlugin({ mode: "server", src: resolve(`${basePluginPath}/og-image-canonical-urls.server`) });
|
|
854
|
+
for (const componentDir of config.componentDirs) {
|
|
855
|
+
const path = resolve(nuxt.options.srcDir, "components", componentDir);
|
|
856
|
+
if (fs.existsSync(path)) {
|
|
857
|
+
kit.addComponentsDir({
|
|
858
|
+
path,
|
|
859
|
+
island: true
|
|
860
|
+
});
|
|
861
|
+
} else if (!defaultComponentDirs.includes(componentDir)) {
|
|
862
|
+
logger_js.logger.warn(`The configured component directory \`./${pathe.relative(nuxt.options.rootDir, path)}\` does not exist. Skipping.`);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
800
865
|
const ogImageComponentCtx = { components: [] };
|
|
801
866
|
nuxt.hook("components:extend", (components) => {
|
|
802
867
|
ogImageComponentCtx.components = [];
|
|
@@ -925,20 +990,23 @@ declare module '#og-image/unocss-config' {
|
|
|
925
990
|
// @ts-expect-error runtime type
|
|
926
991
|
isNuxtContentDocumentDriven: config.strictNuxtContentPaths || !!nuxt.options.content?.documentDriven
|
|
927
992
|
};
|
|
993
|
+
if (nuxt.options.dev) {
|
|
994
|
+
runtimeConfig.componentDirs = config.componentDirs;
|
|
995
|
+
}
|
|
928
996
|
nuxt.hooks.callHook("nuxt-og-image:runtime-config", runtimeConfig);
|
|
929
997
|
nuxt.options.runtimeConfig["nuxt-og-image"] = runtimeConfig;
|
|
930
998
|
});
|
|
931
999
|
if (nuxt.options.dev) {
|
|
932
|
-
setupDevHandler(config,
|
|
1000
|
+
setupDevHandler(config, resolver);
|
|
933
1001
|
setupDevToolsUI(config, resolve);
|
|
934
1002
|
} else if (isNuxtGenerate()) {
|
|
935
|
-
setupGenerateHandler(config,
|
|
1003
|
+
setupGenerateHandler(config, resolver);
|
|
936
1004
|
} else if (nuxt.options.build) {
|
|
937
|
-
await setupBuildHandler(config,
|
|
1005
|
+
await setupBuildHandler(config, resolver);
|
|
938
1006
|
}
|
|
939
1007
|
if (nuxt.options.build)
|
|
940
1008
|
kit.addServerPlugin(resolve("./runtime/server/plugins/prerender"));
|
|
941
|
-
setupPrerenderHandler(config,
|
|
1009
|
+
setupPrerenderHandler(config, resolver);
|
|
942
1010
|
}
|
|
943
1011
|
});
|
|
944
1012
|
|
package/dist/module.d.cts
CHANGED
package/dist/module.d.mts
CHANGED
package/dist/module.d.ts
CHANGED