Skip to content

Commit 2b0420c

Browse files
authored
Merge pull request #207 from piyush97/og-image-fixes
Astro update
2 parents 8443e97 + bf90ca5 commit 2b0420c

File tree

25 files changed

+1068
-243
lines changed

25 files changed

+1068
-243
lines changed

bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@upstash/redis": "^1.35.3",
4545
"@vercel/og": "^0.6.8",
4646
"@vercel/speed-insights": "^1.2.0",
47-
"astro": "^5.13.3",
47+
"astro": "^5.13.4",
4848
"ioredis": "^5.7.0",
4949
"node-fetch": "^3.3.2",
5050
"pg": "^8.16.3",

pnpm-lock.yaml

Lines changed: 150 additions & 150 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 74 additions & 0 deletions
Loading
Lines changed: 49 additions & 0 deletions
Loading

scripts/public/rss.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link>https://piyushmehta.com</link>
66
<description>Articles and tutorials on React.js, web development, and software engineering by Piyush Mehta.</description>
77
<language>en-us</language>
8-
<lastBuildDate>Tue, 26 Aug 2025 17:21:05 GMT</lastBuildDate>
8+
<lastBuildDate>Wed, 27 Aug 2025 16:34:35 GMT</lastBuildDate>
99
<generator>Static RSS Generator</generator>
1010
<copyright>Copyright 2025 Piyush Mehta. All rights reserved.</copyright>
1111
<managingEditor>hello@piyushmehta.com (Piyush Mehta)</managingEditor>

src/components/SEO.astro

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ generateTwitterImageUrl,
99
optimizeKeywords,
1010
sanitizeDescription,
1111
validateImageForSocialSharing
12-
} from '../utils/seo-optimization';
12+
} from '../utils/og-generator';
1313
1414
export interface Props {
1515
title: string;
@@ -54,20 +54,47 @@ const baseUrl = Astro.url.origin || Astro.site?.toString() || 'https://piyushmeh
5454
const optimizedDescription = sanitizeDescription(description);
5555
const canonicalUrl = canonical || generateCanonicalUrl(Astro.url.pathname, baseUrl);
5656
57-
// Handle image metadata with full OG Protocol compliance and generated image fallback
58-
const imageMetadata: ImageMetadata = extractImageMetadata(
59-
image,
60-
baseUrl,
61-
{
62-
title,
63-
description: optimizedDescription,
64-
type,
65-
publishedTime,
66-
tags,
67-
template: ogTemplate,
68-
theme: ogTheme,
69-
}
70-
);
57+
// Handle image metadata with full OG Protocol compliance
58+
// Prioritize existing images over generated ones for better social media compatibility
59+
let imageMetadata: ImageMetadata;
60+
61+
if (image && typeof image === 'string') {
62+
// Use the provided image URL directly
63+
imageMetadata = {
64+
url: image.startsWith('http') ? image : `${baseUrl}${image}`,
65+
secureUrl: image.startsWith('http') ? image : `${baseUrl}${image}`,
66+
type: 'image/jpeg',
67+
width: 1200,
68+
height: 630,
69+
alt: `${title} - ${author}`,
70+
};
71+
} else if (image && typeof image === 'object' && image.url) {
72+
// Use the provided image object
73+
const imageUrl = image.url.startsWith('http') ? image.url : `${baseUrl}${image.url}`;
74+
imageMetadata = {
75+
url: imageUrl,
76+
secureUrl: imageUrl,
77+
alt: image.alt || `${title} - ${author}`,
78+
width: image.width || 1200,
79+
height: image.height || 630,
80+
type: image.type || 'image/jpeg',
81+
};
82+
} else {
83+
// Fallback to generated OG image only when no image is provided
84+
imageMetadata = extractImageMetadata(
85+
null, // No image provided
86+
baseUrl,
87+
{
88+
title,
89+
description: optimizedDescription,
90+
type,
91+
publishedTime,
92+
tags,
93+
template: ogTemplate,
94+
theme: ogTheme,
95+
}
96+
);
97+
}
7198
7299
// Generate Twitter-optimized image URL
73100
const twitterImageUrl = generateTwitterImageUrl({

src/components/blog/BloomFilterDemo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const BloomFilterDemo: React.FC<BloomFilterDemoProps> = () => {
9797
<div className="flex gap-2 mb-2">
9898
{filter.bits.map((bit, index) => (
9999
<div
100-
key={`bit-${index}`}
100+
key={`bit-${index}-${bit}`}
101101
className={`w-12 h-12 rounded-full flex items-center justify-center text-white font-bold ${
102102
bit ? 'bg-green-500' : 'bg-gray-400'
103103
}`}

src/content/blog/astro-v5-9-content-security-policy/index.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ tags:
1616
'Framework',
1717
'Performance',
1818
]
19+
image:
20+
url: '/blog/astro-v5-9-content-security-policy/images/astro-csp-cover.jpeg'
21+
alt: 'Astro 5.9 Content Security Policy implementation illustration'
1922
draft: false
2023
---
2124

0 commit comments

Comments
 (0)