Skip to content

Commit

Permalink
fix: socialImageUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
vhnam committed May 27, 2024
1 parent ac44024 commit 86bd6c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import "../styles/global.scss";
export interface Props {
title?: string;
description?: string;
image?: string;
cover?: string;
articleDate?: string;
}
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const { title, description, cover, articleDate } = Astro.props;
const {
title,
description,
image = "/placeholder-social.jpg",
articleDate,
} = Astro.props;
const expectedTitle = title ? `${title} | ${SITE_TITLE}` : SITE_TITLE;
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const socialImageURL = new URL(
cover ? cover : "/placeholder-social.jpg",
Astro.url
).href;
---

<!-- Global Metadata -->
Expand Down Expand Up @@ -50,7 +49,7 @@ const expectedTitle = title ? `${title} | ${SITE_TITLE}` : SITE_TITLE;
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={expectedTitle} />
<meta property="og:description" content={description ?? SITE_DESCRIPTION} />
<meta property="og:image" content={new URL(image, Astro.url)} />
<meta property="og:image" content={socialImageURL} />
{
articleDate && (
<>
Expand All @@ -68,7 +67,7 @@ const expectedTitle = title ? `${title} | ${SITE_TITLE}` : SITE_TITLE;
property="twitter:description"
content={description ?? SITE_DESCRIPTION}
/>
<meta property="twitter:image" content={new URL(image, Astro.url)} />
<meta property="twitter:image" content={socialImageURL} />

<!-- RSS auto-discovery -->
<link
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/PostLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const articleDate = new Date(pubDate).toISOString();
<BaseHead
title={title}
description={description}
image={cover}
cover={cover?.src}
articleDate={articleDate}
/>
</head>
Expand Down

0 comments on commit 86bd6c3

Please sign in to comment.