From b4f5971cbc9977df4c5782ad47a65291b7e16def Mon Sep 17 00:00:00 2001 From: grassblock Date: Wed, 14 May 2025 22:33:35 +0800 Subject: [PATCH] fix: image still generated when there are featured.* image files --- src/pages/post/[slug]/featured.png.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/post/[slug]/featured.png.js b/src/pages/post/[slug]/featured.png.js index c0fe5e1..449cf73 100644 --- a/src/pages/post/[slug]/featured.png.js +++ b/src/pages/post/[slug]/featured.png.js @@ -13,19 +13,20 @@ export async function getStaticPaths() { async function getExternalImage(post) { const featuredImages = import.meta.glob(`/src/content/posts/*/featured.*`, {import: 'default', eager: true}); const matchedImage = Object.keys(featuredImages).find(path => path.includes(post.slug)); - let matchedImage_src; + let matchedImage_; if (matchedImage) { - matchedImage_src = await getImage({src: featuredImages[matchedImage], format: 'webp'}) || null; + matchedImage_ = await getImage({src: featuredImages[matchedImage], format: 'webp'}) || null; } - return matchedImage_src; + return matchedImage_?.src; } // This function dynamically generates og:images for posts that don't have a featured image export async function GET({ props }) { const {post} = props; + const ExternalImageURL = await getExternalImage(post); try { // Check if a custom cover image already exists - if (post.data.cover && await getExternalImage(post)) { + if (post.data.cover || ExternalImageURL) { // Redirect to the existing image return new Response(null); }