When you include the layout frontmatter property in an .md file, all of your frontmatter YAML values are available to the layout file.
Create a new file at src/layouts/MarkdownPostLayout.astro
Copy the following code into MarkdownPostLayout.astro
Add the following frontmatter property in post-1.md
Check your browser preview again at http://localhost:4321/posts/post-1 and notice what the layout has added to your page.
Add the same layout property to your two other blog posts post-2.md and post-3.md. Verify in your browser that your layout is also applied to these posts.
Challenge: Identify items common to every blog post, and use MarkdownPostLayout.astro to render them, instead of writing them in your Markdown in post-1.md and in every future blog post.
Here’s an example of refactoring your code to include the pubDate in the layout component instead of writing it in the body of your Markdown:
Refactor as much as you think is useful to you, and add as much to your layout as you want, remembering that everything that you add to your layout is one less thing you will write in each and every blog post!
Here is an example of a refactored layout that leaves only individual blog post content rendered by the slot. Feel free to use this, or create your own!