Skip to content

Commit

Permalink
fix: correctly determine paths
Browse files Browse the repository at this point in the history
  • Loading branch information
shepherdjerred committed Jul 1, 2024
1 parent 6236085 commit adc97a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit adc97a2

Please sign in to comment.