fix: build

This commit is contained in:
Princesseuh 2023-09-22 11:43:48 +02:00
parent 83eac94b38
commit 207edd65ec
No known key found for this signature in database
GPG key ID: 105BBD6D57F2B0C0

View file

@ -98,27 +98,26 @@ export async function getImage(
? await service.getSrcSet(validatedOptions, imageConfig) ? await service.getSrcSet(validatedOptions, imageConfig)
: []; : [];
let imageURL = await getFinalURL(validatedOptions); let imageURL = await service.getURL(validatedOptions, imageConfig);
let srcSets: SrcSetValue[] = await Promise.all( let srcSets: SrcSetValue[] = await Promise.all(
srcSetTransforms.map(async (srcSet) => ({ srcSetTransforms.map(async (srcSet) => ({
url: await getFinalURL(srcSet.transform), url: await service.getURL(srcSet.transform, imageConfig),
descriptor: srcSet.descriptor, descriptor: srcSet.descriptor,
attributes: srcSet.attributes, attributes: srcSet.attributes,
})) }))
); );
async function getFinalURL(transform: ImageTransform) { if (
// In build and for local services, we need to collect the requested parameters so we can generate the final images isLocalService(service) &&
if ( globalThis.astroAsset.addStaticImage &&
isLocalService(service) && !(isRemoteImage(validatedOptions.src) && imageURL === validatedOptions.src)
globalThis.astroAsset.addStaticImage && ) {
// If `getURL` returned the same URL as the user provided, it means the service doesn't need to do anything imageURL = globalThis.astroAsset.addStaticImage(validatedOptions);
!(isRemoteImage(transform.src) && imageURL === transform.src) srcSets = srcSetTransforms.map((srcSet) => ({
) { url: globalThis.astroAsset.addStaticImage!(srcSet.transform),
return globalThis.astroAsset.addStaticImage(transform); descriptor: srcSet.descriptor,
} else { attributes: srcSet.attributes,
return await service.getURL(transform, imageConfig); }));
}
} }
return { return {