Add a blog to an Astro site
Astro renders on the server or at build time, which is what a blog wants: every post is plain HTML. One list page and one dynamic route. About fifteen minutes.
Before you start
- An Astro project
- A project API key from Developer → API keys
Install and connect
bash
npm install cmskite marked.env
bash
CMSKITE_API_KEY=csk_live_...src/pages/blog/[slug].astro
astro
---
import { createCMSKite } from 'cmskite'
import { marked } from 'marked'
export async function getStaticPaths() {
const cms = createCMSKite({ apiKey: import.meta.env.CMSKITE_API_KEY })
const paths = []
for await (const post of cms.posts.all()) paths.push({ params: { slug: post.slug }, props: { post } })
return paths
}
const { post } = Astro.props
const html = post.bodyFormat === 'markdown' ? await marked.parse(post.body) : post.body
---
<article>
<h1>{post.title}</h1>
<Fragment set:html={html} />
</article>Static or on demand
With getStaticPaths the posts are read when you build, so a new post needs a new build. Point a webhook at your host's deploy hook to rebuild on every publish. Or render on demand with an adapter and drop getStaticPaths, reading the post with cms.posts.findBySlug(Astro.params.slug).
Check that it works
- Publish a short test post in the dashboard
- Open /blog on your deployed site in a private window and reload. The post should be in the list within a minute
- Open the post. Its address should be your site's, not cmskite.com
- Delete or unpublish the test post when you are done







