---
title: Welcome to my blog!
date: 2023-10-15
summary: How I built my blog
cowsay: Hello World!
---
import CowSay from "@components/blog/CowSay.astro";
## Hey there
I decided to make this blog as a way to track my progress in learning new things.
I hope you enjoy your stay!
This first post is going into a bit of detail about how I made this blog.
## Making The Basic Blog
Astro has a wonderful feature called the [content framework](https://docs.astro.build/en/guides/content-collections/), an extremely powerful way to easily
create many pages with simple markdown and some frontmatter.
First thing you have to to do is create a folder called `content` in the src directory.
I already had some content setup because of the projects parts of this site.
Inside the content folder you place a `config.ts` which will contain the schemas
for your content's frontmatter. I'll just focus on my blog posts for now.
```ts
const blogPostsCollection = defineCollection({
schema: z.object({
title: z.string(),
date: z.date(),
summary: z.string(),
cowsay: z.string()
})
});
```
This contains the metadata each blog post will need to have in order for my site
to render it.
Then, we export an object named `collections` which Astro will pick
up and generate TS bindings for.
```ts
export const collections = {
posts: blogPostsCollection
};
```
Now we can get to writing some content! Make a folder with the
same name as the _key_ of the collection you want to write for. In this case, `posts`.
Then create a markdown file and start writing! Here's a little excerpt
of what [this page looks like](https://github.com/Bwc9876/portfolio-site/tree/main/src/content/posts/hello_world.mdx):
```md
---
title: Welcome to my blog!
date: 2023-10-15
summary: How I built my blog.
cowsay: Hello World!
---
## Hey there
```
The frontmatter is the part between the `---` and `---`. This is where you put
metadata for the post. The `cowsay` field is a special one that I made up. It
changes what the cow says in the header of the page. I'll get to that later.
Now that we have some content, we can start writing some code to render it!
I start off by making a `blog` folder in the `src/pages` directory. This is where
all my blog related pages will go. I then make a `index.astro` file which will
be a directory of all posts on the site.
```astro
---
import Layout from "@layouts/Layout.astro";
import { getCollection } from "astro:content";
const blogEntries = await getCollection("posts");
---
Here you'll find my blog posts, most recent first
{p.data.summary} Read More
The Cowsay - Ben C's Blog
}
{p.data.title}
{p.data.date.toLocaleDateString("en-us", {
weekday: "long",
year: "numeric",
month: "short",
day: "numeric"
})}
>
))
}
{entry.data.title}
{cowText}
```
Now I can link it up in my blog post page!
```astro