An Astro blog engine like no other

Meet the Astro blog engine that integrates with your website using a straightforward API. Smooth, simple, and tasty content integration — that’s Butter.

Posted on November 28, 2023

Intuitive admin interface

So easy to use. So easy to customize. You’re going to love the blog you build with ButterCMS.

Handy integration with Astro

Our Astro blog engine has a simple content API and drop-in SDKs that make the magic happen in minutes, not hours.

A truly zero-maintenance solution

With ButterCMS, you’ll never worry about security upgrades, hosting, or performance again.

You've got better things to do than build another blog

Drop our Astro blog engine into your app, and get back to more interesting problems.

ButterCMS is an API-based blog engine that integrates seamlessly with new and existing Astro apps. It's great for SEO, and provides a clean and modern user interface that your marketing team will love. You can deploy ButterCMS in minutes using our Astro API client. 

That leaves plenty of time for you and your marketing team to do what you do best: create killer apps with killer content. 

Play video

See how Butter’s API enables you to launch a flexible blog with amazing SEO using your existing tech stack.

G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award G2 crowd review award

Best blog engine on the market

headshot of Hampton Catl

After shopping the market, it was clear that ButterCMS was the perfect choice. It allows our developers to build powerful components and makes it easy for our marketing team to drive a better customer experience. Hampton Catlin Creator of Sass and Haml

Deploy our Astro Starter in 30 seconds

Or follow the below commands to clone a copy of the repo from github, install dependencies, set your free Butter token, and run your local server on localhost:3000/.

$ git clone https://github.com/ButterCMS/astro-starter-buttercms.git
$ cd astro-starter-buttercms
$ npm install
$ echo 'ASTRO_APP_BUTTER_CMS_API_KEY=' >> .env
$ npm run start

Built to make content marketing easy

ButterCMS is the best Astro blog engine for a simple reason: Astro developers can build solutions that marketing people love. Our API allows your content gurus to quickly spin up high-converting blog templates, sidebars, related content features, and more, all using simple drag-and-drop functionality.

  • Use main domain (improves SEO)
  • Friendly admin interface
  • Upload images, video, and other media
  • Edit URL slugs and meta tags
  • Tags and categories
  • Author profiles
  • RSS/Atom feeds
  • Search
  • Webhooks
  • And more...

The simplest Astro blog engine you'll find

Our simple setup saves you time and money. Take us for a spin to see for yourself!

headshot of LUKE GARDNER

It's the epitome of plug-and-play simplicity for content creators. It does exactly what I need it to. LUKE GARDNER, CONTENT SPECIALIST, PRINTAVO

Fast integration with any Astro app

Our mission was to make it easy to integrate Butter with your existing Astro app in minutes. It’s so simple! To demonstrate, here’s a mini tutorial to give you a feel for the process of adding Butter to your Astro app.

Of course, you can also use our Pages and Collections to do advanced content modeling. For a full integration guide, check out our Official Guide for the ButterCMS Astro API client.

Play video

See how easily you can integrate the ButterCMS Pages API with your Astro app.

Seamless Astro components

Empower your marketing team to create a customized blog engine that aligns perfectly with your Astro components. 

Components are the essential building blocks of any Astro app, and ButterCMS handles them with ease. 

Our drag and drop interface makes it simple to structure your content to match existing Astro components and to create new reusable components whenever you need them.

The best Astro blog engine for SEO

ButterCMS gives you absolute control over on-page SEO ranking factors. Key SEO variables are built into our default post template, giving your marketing team direct access to configure all of these settings, and more.

  • Page title
  • Post tags and categories
  • META description
  • URL slug
  • Featured image / Open Graph image
  • Image ALT tags
  • Link anchor text

ButterCMS saves you development time

Most customers get our Astro blog engine up and running in less than an hour. Try it yourself!

headshot of DILLON BURNS

Simple as can be, with powerful features and great customer support. DILLON BURNS, FRONT END DEVELOPER, KEYME

How to integrate ButterCMS into your Astro application

Integrating the Butter blog engine into your Astro app is dead simple. Here's a mini tutorial to get a feel for setting up your blog home and blog post pages. 

For a full integration guide, check out our Official Astro Guide. Before you get started, you'll want to install ButterCMS into your app, or you can load from CDN.

There are a number of ways to integrate your ButterCMS blog into your app. The easiest is with Server-side Rendering, or SSR.

To switch to Server-side Rendering, open your astro.config.mjs file and add the output:'server' option to your defineConfig():

export default defineConfig({
  output: 'server',
});

We're going to be making three different routes:

  • A main blog view, which will server as the basis of your blog home and display a list of your 10 most recent posts,
  • An archive routes to let users paginate through older blog posts, which passes the post slug in as a parameter,
  • And individual blog post pages.

Let's start by setting up our individual blog post pages. This will include information such as author, publish date, and categories. See a full list of available post properties in our API reference.

Create a new folder, blog, inside of /src/pages/. Then, create a file, [slug].astro.

/src/pages/blog/[slug].astro:

---
//code block 
import Butter from "buttercms";

/* We recommend instantiating Butter with a utility class, such as this example:
https://github.com/ButterCMS/astro-starter-buttercms/blob/main/src/utils/buttercmssdk.jsx,
but we'll just do it in this file for now */

const butterCMS = Butter("your_api_token");

// Let's pull the slug from the Astro params and grab our posts from Butter
const postSlug = Astro.params.slug
const postData = await butterCMS.post.retrieve(postSlug);

// To make the template simpler, we'll store our needed data as just post
const post = postData.data.data

---
<!---html block-->
<html>
  <head>
    <title>{ post.seo_title }</title>
  </head>
  <body>
    <h1>{ post.title }</h1>
    <!-- Post author + Publish date. We're not actually going to set up routes/pages
    for authors and categories, but it's shown here for reference-->
    <p>
      Posted by <a href={"/blog/author/" + post.author.slug + "/"}>{ post.author.first_name } { post.author.last_name }</a> on { post.published }
    </p>
    <ul>
    <!-- Post categories -->
      { post.categories.map((category) => (
        <li><a href={"/blog/category/" + category.slug + "/"}>{ category.name } </a></li>
      ))}
    </ul>
    <Fragment set:html={ post.body }/>
  </body>
</html>

For the blog list routes, because so much of the code will be similar, we're going to expand our app out with a utility function and a layout that will avoid too much repetition.

Let's start with our utility file, which will allow us to make our call to Butter to get our post list. It will also return some metadata we can use for pagination.

Make a new directory inside of your srcfolder, utils, and create a file, BlogRoll.js.

/src/utils/BlogRoll.js:

import Butter from 'buttercms';
const butterCMS = Butter('your_api_token');

async function getPostsData(page = null) {
  /* Grab posts from Butter. Specify number of results to fetch with page_size.
  For example, you can set to "1" to test pagination functions*/
  const postsData = await butterCMS.post.list({ page_size: 10, page: page });
  // Get next and previous pages for pagination
  const nextPage = postsData.data.meta.next_page;
  const previousPage = postsData.data.meta.previous_page;
  const posts = postsData.data.data;
  return { nextPage, previousPage, posts };
}

export default getPostsData;

Great. Now, let's create our layout file, which will get recycled between the two different blog views.

Make a new file inside of your src/layouts/folder, BlogLayout.astro.

/src/layouts/BlogLayout.astro:

---
//code block

const {posts, previousPage, nextPage, page } = Astro.props
---
<html>
  <head>
      <!-- Note that conditional display of html in Astro uses jsx logical operators and 
      ternary expressions-->
      <title>{page ? "Blog Posts, Page " + page : "All Blog Posts" }</title>
  </head>
  <body>
    <h1>{page ? "Blog Posts, Page " + page : "All Blog Posts" }</h1>
    <!-- List of Posts -->
    <ul>
      { posts.map((post) => (
      <li><a href={"/blog/" + post.slug + "/"}>{ post.title }</a></li>
        ))}
    </ul>

    <!-- List of Posts -->
    { previousPage ? <a href={"/blog/page/" + previousPage}>Previous Page</a> : "Previous Page"}
    { nextPage ? <a href={"/blog/page/" + nextPage}>Next Page</a> : "Next Page"}
  </body>
</html>

Great. Now that we've created our utility file and our Layout, it's time to create our blog list views.

Inside of your blog folder, make a new file, index.astro.

/src/pages/blog/index.astro:

---
//code block 
import BlogLayout from "../../layouts/BlogLayout.astro"
import getPostsData from "../../utils/BlogRoll.js"

const {nextPage, previousPage, posts, page} = await getPostsData();

---
<BlogLayout 
  nextPage={nextPage} previousPage={previousPage} posts={posts}>
</BlogLayout>

Inside of your blog folder, also make a new folder, page, and create a [page].astro file.

/src/pages/blog/page/[page].astro:

---
//code block 
import BlogLayout from "../../../layouts/BlogLayout.astro"
import getPostsData from "../../../utils/BlogRoll.js"

// Get page from URL Route
const page = Astro.params.page;
const {nextPage, previousPage, posts} = await getPostsData(page);

---
<BlogLayout 
  page={page} nextPage={nextPage} previousPage={previousPage} posts={posts}>
</BlogLayout>

That's it! If you restart your development server, you should be able to access the following new routes in your app: /blog/, /blog//, and /blog/page//

Get Started for Free

Try Butter free for 14 days

See for yourself what makes Butter the best Astro blog engine out there. Click the button below to sign up for your free 14-day trial.