Skip to content

Commit a8edba0

Browse files
committed
add og image support
1 parent ae86003 commit a8edba0

6 files changed

Lines changed: 18 additions & 1 deletion

File tree

187 KB
Loading

src/components/Navigation.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
}
2626

2727
.brand__image {
28+
margin: 0;
2829
width: 3.5rem;
2930
height: 3.5rem;
3031
border-radius: 50%;

src/content/blog/2026-01-17-3d-printer.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ description:
77
have said no. My experience of 3D printers back when I was in college was that
88
they were very slow, expensive, frequently failed mid-print, and needed
99
constant calibration..."
10+
image: /images/2026-01-17-3d-printer.jpg
1011
---
1112

1213
import STLViewer from "../../components/STLViewer.tsx";

src/content/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const blog = defineCollection({
1313
return val || [];
1414
}),
1515
description: z.string().optional(),
16+
image: z.string().optional(),
1617
draft: z.boolean().optional().default(false),
1718
}),
1819
});

src/layouts/BaseLayout.astro

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
export interface Props {
33
title: string;
44
description?: string;
5+
image?: string;
56
}
67
78
const {
89
title,
910
description = "Brooke Hatton, Full Stack Developer. 1st Class Honours, BEng Computer Science, University Of York.",
11+
image,
1012
} = Astro.props;
1113
1214
// Import the global stylesheet
@@ -25,6 +27,18 @@ import "../styles/global.css";
2527
/>
2628
<title>{title}</title>
2729

30+
<!-- Open Graph / Social Media Preview -->
31+
<meta property="og:title" content={title} />
32+
<meta property="og:description" content={description} />
33+
{image && <meta property="og:image" content={new URL(image, Astro.site).href} />}
34+
<meta property="og:type" content="website" />
35+
36+
<!-- Twitter Card -->
37+
<meta name="twitter:card" content="summary_large_image" />
38+
<meta name="twitter:title" content={title} />
39+
<meta name="twitter:description" content={description} />
40+
{image && <meta name="twitter:image" content={new URL(image, Astro.site).href} />}
41+
2842
<!-- Fonts -->
2943
<link rel="preconnect" href="https://fonts.googleapis.com" />
3044
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function formatDate(date: Date): string {
3131
}
3232
---
3333

34-
<BaseLayout title={post.data.title} description={post.data.description}>
34+
<BaseLayout title={post.data.title} description={post.data.description} image={post.data.image}>
3535
<Navigation />
3636
<article class="post">
3737
<header class="post__header header--xl">

0 commit comments

Comments
 (0)