Skip to content

Commit 75bb4fc

Browse files
committed
feat: add image to blog posts
1 parent 3b663f7 commit 75bb4fc

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/content/posts/why-astro.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: "Why Astro?"
33
pubDate: 2023-12-21
44
description: "My first blog post, which explains my reasoning for choosing Astro to build my personal website"
55
author: "Lucas Machado"
6+
image:
7+
url: "https://docs.astro.build/assets/full-logo-light.png"
8+
alt: "The full Astro logo."
69
tags: ["astro", "blogging", "learning in public"]
710
---
811

src/layouts/BlogLayout.astro

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import DateTime from "../components/DateTime.astro";
55
const { frontmatter } = Astro.props;
66
---
77

8-
<Layout title={frontmatter.title} description={frontmatter.description}>
8+
<Layout
9+
title={frontmatter.title}
10+
description={frontmatter.description}
11+
image={frontmatter.image}
12+
>
913
<article
1014
class="prose lg:prose-xl prose-slate dark:prose-invert hover:prose-headings:underline prose-headings:text-teal-300"
1115
>
1216
<h1 class="leading-tight font-bold text-3xl text-slate-200">
1317
{frontmatter.title}
1418
</h1>
1519
<DateTime pubDate={frontmatter.pubDate} />
20+
<img src={frontmatter.image.url} alt={frontmatter.image.alt} />
1621
<slot />
1722
<p class="pt-8 font-medium text-slate-200">
1823
Written by {frontmatter.author}

src/layouts/Layout.astro

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import Footer from "../components/Footer.astro";
66
interface Props {
77
title: string;
88
description: string;
9+
image: {
10+
url: string;
11+
alt: string;
12+
};
913
}
1014
11-
const { title, description } = Astro.props;
15+
const { title, description, image } = Astro.props;
1216
---
1317

1418
<!doctype html>
@@ -22,21 +26,15 @@ const { title, description } = Astro.props;
2226
<meta property="og:title" content={title} />
2327
<meta property="og:description" content={description} />
2428
<meta property="og:type" content="website" />
25-
<meta
26-
property="og:image"
27-
content="https://avatars.githubusercontent.com/u/73367620?v=4"
28-
/>
29+
<meta property="og:image" content={image.url} />
2930
<meta property="og:url" content={Astro.url.href} />
3031
<meta name="twitter:card" content="summary_large_image" />
3132
<meta name="twitter:site" content="@lucascarmac" />
3233
<meta name="twitter:creator" content="@lucascarmac" />
3334
<meta name="twitter:title" content={title} />
3435
<meta name="twitter:description" content={description} />
35-
<meta
36-
name="twitter:image"
37-
content="https://avatars.githubusercontent.com/u/73367620?v=4"
38-
/>
39-
<meta name="twitter:image:alt" content={description} />
36+
<meta name="twitter:image" content={image.url} />
37+
<meta name="twitter:image:alt" content={image.alt} />
4038
<meta name="twitter:url" content={Astro.url.href} />
4139
<meta name="twitter:domain" content={Astro.url.host} />
4240
<title>{title}</title>

src/pages/index.astro

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const metadata = {
66
title: "Lucas Machado",
77
description:
88
"Lucas Machado is a software engineer who builds accessible and interactive user experiences for the web.",
9+
image: {
10+
url: "https://avatars.githubusercontent.com/u/73367620?v=4",
11+
alt: "A picture of Lucas, a young man with glasses, a beard and a black t-shirt, smiling on a bright day outside",
12+
},
913
};
1014
---
1115

0 commit comments

Comments
 (0)