feat: mock when running locally

This commit is contained in:
Cory Dransfeldt 2024-02-08 16:42:17 -08:00
parent 12f4929dd3
commit 6757a60134
No known key found for this signature in database
22 changed files with 1342 additions and 300 deletions

View file

@ -18,7 +18,7 @@ export const img = async (
sizes = '90vw',
formats = ['avif', 'webp', 'jpeg']
) => {
const isLocal = src.includes('src/assets');
const isLocal = src?.includes('src/assets');
const imageExists = async () => {
try {
return await fetch(src, { method: 'HEAD' }).then((res) => res.ok);
@ -69,5 +69,9 @@ export const img = async (
);
};
return isLocal ? await generateImage() : await imageExists().then(async (exists) => (exists ? await generateImage() : await generatePlaceholder()));
};
if (process.env.ELEVENTY_PRODUCTION) {
return isLocal ? await generateImage() : await imageExists().then(async (exists) => (exists ? await generateImage() : await generatePlaceholder()));
} else {
return await generatePlaceholder();
}
};