astro-ghostcms/.pnpm-store/v3/files/fd/6366bf6f819904e411a9f610fca...

27 lines
774 B
Plaintext
Raw Permalink Normal View History

2024-02-14 14:10:47 +00:00
import { z } from "zod";
import { emitESMImage } from "../assets/utils/emitAsset.js";
function createImage(pluginContext, entryFilePath) {
return () => {
return z.string().transform(async (imagePath, ctx) => {
const resolvedFilePath = (await pluginContext.resolve(imagePath, entryFilePath))?.id;
const metadata = await emitESMImage(
resolvedFilePath,
pluginContext.meta.watchMode,
pluginContext.emitFile
);
if (!metadata) {
ctx.addIssue({
code: "custom",
message: `Image ${imagePath} does not exist. Is the path correct?`,
fatal: true
});
return z.never();
}
return { ...metadata, ASTRO_ASSET: metadata.fsPath };
});
};
}
export {
createImage
};