Skip to content

Commit 56acede

Browse files
committed
Blog improvement with nested layout and component
1 parent 583f67c commit 56acede

7 files changed

Lines changed: 35 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
const { url, title } = Astro.props;
3+
---
4+
5+
<li><a href={url}>{title}</a></li>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
import BaseLayout from './BaseLayout.astro';
3+
const { frontmatter } = Astro.props;
4+
---
5+
<BaseLayout pgTitle={frontmatter.title}>
6+
<p>Written by {frontmatter.author}</p>
7+
<p>Published on: {frontmatter.pubDate.toString().slice(0,10)}</p>
8+
<img src={frontmatter.image.url} width="300" alt={frontmatter.image.alt} />
9+
<slot />
10+
</BaseLayout>

tutorial/src/pages/blog.astro

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22
import '../styles/global.css';
33
import BaseLayout from '../layouts/BaseLayout.astro';
4+
import BlogPost from '../components/BlogPost.astro';
5+
6+
const allPosts = Object.values(import.meta.glob('./posts/*.md', { eager: true }));
47
58
const pgTitle = "My Astro Learning Blog";
69
---
710

811
<BaseLayout pgTitle={pgTitle}>
912
<p>This is where I will post about my journey learning Astro.</p>
1013
<ul>
11-
<a href="/myAstroTest/posts/post-1">My first blog post</a>
12-
<a href="/myAstroTest/posts/post-2">Post 2</a>
13-
<a href="/myAstroTest/posts/post-3">Post 3</a>
14+
{allPosts.map((post: any) => <BlogPost url={post.url} title={post.frontmatter.title} />)}
1415
</ul>
1516

1617
</BaseLayout>

tutorial/src/pages/posts/post-1.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
layout: ../../layouts/MDpostLayout.astro
23
title: 'My First Blog Post'
34
pubDate: 2026-04-16
45
description: 'This is the first post of my new Astro blog.'
@@ -8,9 +9,6 @@ image:
89
alt: 'The Astro logo on a dark background with a pink glow.'
910
tags: ["astro", "blogging", "learning in public"]
1011
---
11-
# My First Blog Post
12-
13-
Published on: 2022-07-01
1412

1513
Welcome to my _new blog_ about learning Astro! Here, I will share my learning journey as I build a new website.
1614

tutorial/src/pages/posts/post-2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
layout: ../../layouts/MDpostLayout.astro
23
title: My Second Blog Post
34
author: Astro Learner
45
description: "After learning some Astro, I couldn't stop!"

tutorial/src/pages/posts/post-3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
layout: ../../layouts/MDpostLayout.astro
23
title: My Third Blog Post
34
author: Astro Learner
45
description: "I had some challenges, but asking in the community really helped!"

tutorial/src/pages/posts/post-4.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
layout: ../../layouts/MDpostLayout.astro
3+
title: My Fourth Blog Post
4+
author: Astro Learner
5+
description: "This post will show up on its own!"
6+
image:
7+
url: "https://docs.astro.build/default-og-image.png"
8+
alt: "The word astro against an illustration of planets and stars."
9+
pubDate: 2026-04-17
10+
tags: ["astro", "successes"]
11+
---
12+
13+
This post should show up with my other blog posts, because `import.meta.glob()` is returning a list of all my posts in order to create my list.

0 commit comments

Comments
 (0)