Skip to content
BearMinion

← Blog

Add a blog to an Astro site in one command

Dated posts with a cover and a draft switch, a paginated listing at /blog, and sitemap entries. No plugin, no Markdown pipeline to wire up.

This blog was made with the command in this post, so you're reading the result.

Run one command

In a BearMinion site, run:

npx bearminion add blog

You get a Blog content type:

  • Posts at /blog/<slug>, each with a date, an excerpt, a cover image and a draft switch.
  • Newest first.
  • A listing page at /blog, ten posts to a page, with /blog/page/2 and so on after that.
  • Every published post and listing page in the sitemap.

It writes two files, src/lib/types/blog.ts and src/lib/types/index.ts, and adds one line to src/lib/content-model.ts that passes them to the content model. There is no route file to add: the starter's one route draws every address.

Add --dry-run first if you want to see what it will write.

Write the first post

Restart npm run dev, open the editor and go to Pages → Blog → New entry. A title is enough: the date starts as today.

The Blog list under Pages in the BearMinion editor, with the New entry button
Each content type has its own list under Pages, with New entry.

The date, excerpt, cover and draft switch are in the Fields group; everything else is sections, like any page.

The Fields group of a blog post in the editor: date, excerpt, cover and draft
The post's own fields: date, excerpt, cover and the draft switch.

Then link /blog from your header in the Navigation tab.

Drafts

Turn on draft and the post shows while you edit, but npm run build leaves it out of the site, the listing and the sitemap. Turn it off when it's ready.

Change the fields

src/lib/types/blog.ts is yours. Add a field to its z.object({...}), an author or a reading time, and the editor draws a control for it.

Other kinds of content

A blog is one content type. For case studies, a team list or news, run npx bearminion add type and answer its questions, or pass flags:

npx bearminion add type case-studies --field client:text --field year:number --sort year:desc --listing 6

What it doesn't do yet

There are no tag, author or archive pages and no RSS feed yet. While a type has no entries, a build prints a notice that the collection is empty; that's expected, and the listing shows its empty state.

More in Content types.

Wake the minion.

Run one command, answer three boring questions and watch it do the rest. Template copied, dependencies installed, first commit done.

Now it gets out of your way so you can actually work.

  1. npm create bearminion@latest
  2. Created My Site in my-site
  3. Installed dependencies
  4. →Next: cd my-site, npm run dev