Skip to content

Commit 98c545f

Browse files
committed
Add og:image when blog post has header image
1 parent b4f6cb7 commit 98c545f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/layouts/BaseLayout.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ConditionalProps = (
1919
) & {
2020
title: string;
2121
description?: string | undefined;
22+
image?: string | undefined;
2223
};
2324
2425
export type Props = ConditionalProps & {
@@ -27,7 +28,7 @@ export type Props = ConditionalProps & {
2728
2829
let pathname: string;
2930
const { class: className } = Astro.props;
30-
const { title, description } = Astro.props;
31+
const { title, description, image } = Astro.props;
3132
if ('url' in Astro.props) {
3233
({ url: pathname } = Astro.props);
3334
} else if (Astro.props.request) {
@@ -66,6 +67,7 @@ if ('url' in Astro.props) {
6667
content={description ??
6768
'Personal website for Ben Saufley, a software engineer and illustrator from Portland, Maine.'}
6869
/>
70+
{image && <meta name="og:image" content={image} />}
6971
</head>
7072
<body class={clsx(className)}>
7173
<Header currentPath={pathname} />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const published = dayjs.utc(date).startOf('day');
3636
const { Content } = await post.render();
3737
---
3838

39-
<BaseLayout title={title}>
39+
<BaseLayout title={title} image={img?.url}>
4040
<Post title={title} posted={published} headerImage={img}>
4141
<Content />
4242
</Post>

0 commit comments

Comments
 (0)