mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
Resvg dynamic import
Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Vendored
-1
@@ -9,7 +9,6 @@ export type ImageGeneratorResult = {
|
||||
export declare class ImageGenerator {
|
||||
private args;
|
||||
private satori;
|
||||
private sharp;
|
||||
private cache;
|
||||
private outDir;
|
||||
constructor(args: {
|
||||
|
||||
@@ -9,7 +9,6 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
||||
class ImageGenerator {
|
||||
args;
|
||||
satori;
|
||||
sharp;
|
||||
cache = {};
|
||||
outDir = '';
|
||||
constructor(args) {
|
||||
@@ -18,7 +17,6 @@ class ImageGenerator {
|
||||
}
|
||||
init = async () => {
|
||||
this.satori = await import('satori').then((mod) => mod.default);
|
||||
this.sharp = await import('sharp').then((mod) => mod.default);
|
||||
if (!fs.existsSync(this.outDir))
|
||||
await fsp.mkdir(this.outDir, { recursive: true });
|
||||
};
|
||||
@@ -30,7 +28,9 @@ class ImageGenerator {
|
||||
const absolutePath = path_1.default.join(this.outDir, imageName);
|
||||
const relativePath = path_1.default.join('/', this.args.dir, absolutePath.slice(this.outDir.length));
|
||||
const svg = await this.satori(element, options);
|
||||
await this.sharp(Buffer.from(svg)).png().toFile(absolutePath);
|
||||
const { Resvg } = await import('@resvg/resvg-js').then(module => module);
|
||||
const pngBuffer = new Resvg(svg).render().asPng();
|
||||
await fsp.writeFile(absolutePath, pngBuffer);
|
||||
const url = new URL(this.args.websiteUrl);
|
||||
url.pathname = relativePath;
|
||||
this.cache[hash] = {
|
||||
|
||||
Reference in New Issue
Block a user