From d3630aa5633f5af457f7c0497f8f5f7a0a9c7434 Mon Sep 17 00:00:00 2001 From: madrilene Date: Thu, 12 Sep 2024 14:00:33 +0200 Subject: [PATCH] stop server from terminating if no OG images dir exists --- src/_config/events/svg-to-jpeg.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/_config/events/svg-to-jpeg.js b/src/_config/events/svg-to-jpeg.js index e9faad8..b82a8b7 100644 --- a/src/_config/events/svg-to-jpeg.js +++ b/src/_config/events/svg-to-jpeg.js @@ -1,10 +1,17 @@ -import {promises as fsPromises, existsSync} from 'fs'; +import {promises as fsPromises, existsSync} from 'node:fs'; import path from 'node:path'; import Image from '@11ty/eleventy-img'; + const ogImagesDir = './src/assets/og-images'; export const svgToJpeg = async function () { const socialPreviewImagesDir = 'dist/assets/og-images/'; + + if (!existsSync(socialPreviewImagesDir)) { + console.log('⚠ No OG images dir found'); + return; + } + const files = await fsPromises.readdir(socialPreviewImagesDir); if (files.length > 0) { files.forEach(async function (filename) { @@ -21,6 +28,6 @@ export const svgToJpeg = async function () { } }); } else { - console.log('⚠ No social images found'); + console.log('⚠ No images found on OG images dir'); } };