Skip to content

Commit 1e0917d

Browse files
committed
2 parents 60fde8e + 0d5d989 commit 1e0917d

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/pages/blog/[year]/[slug].astro

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ const { content: processedContent, embeds } = processContentWithPrivacy(post.con
3535
const metadata = {
3636
title: post.title.rendered,
3737
description: post.excerpt.rendered.replace(/<[^>]*>/g, '').substring(0, 160),
38-
openGraph: featuredImage ? {
39-
images: [
40-
{
41-
url: featuredImage.url,
42-
width: featuredImage.width,
43-
height: featuredImage.height,
44-
alt: featuredImage.alt,
45-
},
46-
],
47-
} : undefined,
38+
...(featuredImage && {
39+
openGraph: {
40+
images: [
41+
{
42+
url: featuredImage.url,
43+
width: featuredImage.width,
44+
height: featuredImage.height,
45+
},
46+
],
47+
},
48+
}),
4849
};
4950
---
5051

src/utils/images.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ export const adaptOpenGraphImages = async (
8282
isUnpicCompatible(resolvedImage)
8383
) {
8484
_image = (await unpicOptimizer(resolvedImage, [defaultWidth], defaultWidth, defaultHeight, 'jpg'))[0];
85+
} else if (
86+
typeof resolvedImage === 'string' &&
87+
(resolvedImage.startsWith('http://') || resolvedImage.startsWith('https://'))
88+
) {
89+
// External image without a recognized CDN (e.g. WordPress).
90+
// Pass it through as-is; og:image is consumed remotely by crawlers,
91+
// and the author-provided width/height are authoritative.
92+
return {
93+
url: resolvedImage,
94+
width: image.width,
95+
height: image.height,
96+
};
8597
} else if (resolvedImage) {
8698
const dimensions =
8799
typeof resolvedImage !== 'string' && resolvedImage?.width <= defaultWidth

0 commit comments

Comments
 (0)