Skip to content

Commit 165fb4f

Browse files
committed
Attempt fixing social previews on WhatsApp
1 parent 0721e1b commit 165fb4f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

packages/astro-theme/components/BaseHead.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface Props {
88
title: string;
99
description: string;
1010
image?: string | undefined;
11+
imageWidth?: number | undefined;
12+
imageHeight?: number | undefined;
1113
}
1214
1315
const isBlogPost =
@@ -20,7 +22,7 @@ const canonicalSite = isBlogPost
2022
: Astro.site;
2123
const canonicalURL = new URL(Astro.url.pathname, canonicalSite);
2224
23-
const { title, description, image = "/social/[email protected]" } = Astro.props;
25+
const { title, description, image = "/social/[email protected]", imageWidth, imageHeight } = Astro.props;
2426
2527
const product = productFromUrl(canonicalURL);
2628
const favicon = product?.favicon ?? companyFavicon.src;
@@ -84,6 +86,8 @@ const localised = getLocalisedPaths(Astro.url.pathname, Astro.currentLocale);
8486
<meta property="og:title" content={title} />
8587
<meta property="og:description" content={description} />
8688
<meta property="og:image" content={new URL(image, Astro.url)} />
89+
{imageWidth && <meta property="og:image:width" content={imageWidth} />}
90+
{imageHeight && <meta property="og:image:height" content={imageHeight} />}
8791
<meta property="og:site_name" content={SITE_TITLE} />
8892

8993
<!-- Twitter -->

packages/astro-theme/layouts/BlogPost.astro

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ if (subtitle) {
3535
}
3636
---
3737

38-
<Shell title={titleAndSubtitle} {description} image={heroImage?.src}>
38+
<Shell
39+
title={titleAndSubtitle}
40+
{description}
41+
image={heroImage?.src}
42+
imageWidth={heroImage?.width}
43+
imageHeight={heroImage?.height}
44+
>
3945
{product && <ProductNav {product} />}
4046
<main class="px-6 py-10 w-full max-w-screen-xl mx-auto">
4147
<a

packages/astro-theme/layouts/Shell.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ interface Props {
77
title?: string;
88
description?: string | undefined;
99
image?: string | undefined;
10+
imageWidth?: number | undefined;
11+
imageHeight?: number | undefined;
1012
}
1113
12-
const { title, description, image } = Astro.props;
14+
const { title, description, image, imageWidth, imageHeight } = Astro.props;
1315
---
1416

1517
<!doctype html>
@@ -19,6 +21,8 @@ const { title, description, image } = Astro.props;
1921
title={title || SITE_TITLE}
2022
description={description || SITE_DESCRIPTION}
2123
{image}
24+
{imageWidth}
25+
{imageHeight}
2226
/>
2327
<style is:global>
2428
.dark {

0 commit comments

Comments
 (0)