Skip to content

Commit 0d5d989

Browse files
authored
Merge pull request #7 from mandrasch/claude/wordpress-og-image-retrieval-aotyx
feat: use WordPress featured image as blog post og:image
2 parents a7bd998 + 636fb86 commit 0d5d989

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +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-
// Skip OG images to avoid remote dimension fetching issues during build
38+
...(featuredImage && {
39+
openGraph: {
40+
images: [
41+
{
42+
url: featuredImage.url,
43+
width: featuredImage.width,
44+
height: featuredImage.height,
45+
},
46+
],
47+
},
48+
}),
3949
};
4050
---
4151

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)