Meet the Astro blog engine that integrates with your website using a straightforward API. Smooth, simple, and tasty content integration — that’s Butter.
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.
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.
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.
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.
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.
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 ourAPI 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 yoursrcfolder,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 yoursrc/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>
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//