Skip to content

Commit 9434d85

Browse files
committed
fix: use default-og for twitter card
1 parent af517cd commit 9434d85

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/layouts/Layout.astro

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ const {
1919
} = Astro.props;
2020
2121
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
22+
2223
const socialImageURL = new URL(
2324
ogImage ? ogImage : SITE.ogImage,
2425
Astro.url.origin
25-
);
26+
).href;
27+
28+
const fallbackImageURL = new URL(SITE.ogImage, Astro.url.origin).href;
2629
---
2730

2831
<!DOCTYPE html>
@@ -51,7 +54,12 @@ const socialImageURL = new URL(
5154
<meta property="twitter:url" content={canonicalURL} />
5255
<meta property="twitter:title" content={title} />
5356
<meta property="twitter:description" content={description} />
54-
<meta property="twitter:image" content={socialImageURL} />
57+
<meta
58+
property="twitter:image"
59+
content={socialImageURL.endsWith(".svg")
60+
? fallbackImageURL
61+
: socialImageURL}
62+
/>
5563

5664
<!-- Google Font -->
5765
<link rel="preconnect" href="https://fonts.googleapis.com" />

0 commit comments

Comments
 (0)