diff --git a/src/hook.ts b/src/hook.ts index 5090fd6..9181ea3 100644 --- a/src/hook.ts +++ b/src/hook.ts @@ -54,8 +54,8 @@ async function handlePage({ page, options, render, dir, logger }: HandlePageInpu let pngFile = htmlFile.replace(/\.html$/, ".png"); // remove leading dist/ from the path - pngFile = pngFile.replace("dist/", ""); fs.writeFileSync(pngFile, resvg.render().asPng()); + pngFile = pngFile.replace("dist/", ""); // check that the og:image property matches the sitePath if (pageDetails.image !== pngFile) { diff --git a/src/util.ts b/src/util.ts index b9c0285..e650b28 100644 --- a/src/util.ts +++ b/src/util.ts @@ -30,6 +30,13 @@ export function getImagePath({ url }: { url: URL }): string { target = target + ".png"; } + // Astro creates these as top-level files rather than in a folder + if (target === "/404/index.png") { + return "404.png"; + } else if (target === "/500/index.png") { + return "500.png"; + } + // remove leading slash target = target.slice(1);