Skip to content

Commit 4301d8b

Browse files
fix og image
1 parent ed76d52 commit 4301d8b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/components/BaseHead.astro

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export interface Props {
1111
1212
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
1313
14-
const { title, description, image = "/placeholder-social.png" } = Astro.props;
14+
const {
15+
title,
16+
description,
17+
image = new URL("/placeholder-social.png", Astro.url),
18+
} = Astro.props;
1519
---
1620

1721
<!-- Global Metadata -->
@@ -41,6 +45,6 @@ const { title, description, image = "/placeholder-social.png" } = Astro.props;
4145
<meta property="twitter:url" content={Astro.url} />
4246
<meta property="twitter:title" content={title} />
4347
<meta property="twitter:description" content={description} />
44-
<meta property="twitter:image" content={new URL(image, Astro.url)} />
48+
<meta property="twitter:image" content={image} />
4549

4650
<!-- Third-party scripts -->

src/layouts/BlogPost.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = CollectionEntry<"blog">["data"] & { slug: string };
88
const { title, description, pubDate, updatedDate, heroImage, slug } =
99
Astro.props;
1010
11-
const buildOGURL = (title: string | undefined) => {
11+
export const buildOGURL = (title: string | undefined) => {
1212
const url = new URL("https://image.memp.dev/api");
1313
title && url.searchParams.set("title", `/${slug}`);
1414
return url.toString();

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import { CollectionEntry, getCollection } from "astro:content";
3-
import BlogPost from "../../layouts/BlogPost.astro";
3+
import BlogPost, { buildOGURL } from "../../layouts/BlogPost.astro";
44
55
export async function getStaticPaths() {
66
const posts = await getCollection("blog");
@@ -15,7 +15,11 @@ const post = Astro.props;
1515
const { Content } = await post.render();
1616
---
1717

18-
<BlogPost {...post.data} slug={post.slug}>
18+
<BlogPost
19+
{...post.data}
20+
slug={post.slug}
21+
heroImage={buildOGURL(post.data.title)}
22+
>
1923
<Content />
2024
<script
2125
src="https://utteranc.es/client.js"

0 commit comments

Comments
 (0)