Skip to content

Commit

Permalink
Fix invalid images generation for some slugs with leading slash (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Swithinbank <[email protected]>
  • Loading branch information
julien-deramond and delucis authored Jul 6, 2024
1 parent c552589 commit 9fec927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lucky-seahorses-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro-og-canvas': patch
---

Fixes image generation for slugs with a leading slash in Astro ≥4.10.2
5 changes: 4 additions & 1 deletion packages/astro-og-canvas/src/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function makeGetStaticPaths({
function createOGImageEndpoint({ getSlug = pathToSlug, ...opts }: OGImageRouteConfig): APIRoute {
return async function getOGImage({ params }) {
const pageEntry = Object.entries(opts.pages).find(
(page) => getSlug(...page) === params[opts.param]
(page) => {
const slug = getSlug(...page);
return slug === params[opts.param] || slug.replace(/^\//, "") === params[opts.param];
}
);
if (!pageEntry) return new Response('Page not found', { status: 404 });

Expand Down

0 comments on commit 9fec927

Please sign in to comment.