To migrate from Ghost to Astro, fetch your posts from Ghost’s Content API (or the JSON export), convert each post’s HTML to Markdown, download the images, and load the files into an Astro content collection. Then rebuild Ghost’s URL structure (/post-slug/, /tag/name/) in Astro routes, redirect the RSS feed, and move members to a newsletter service. A Ghost to Astro move typically takes a day for a blog with a few hundred posts.
This guide covers each step with working code. If you’re still deciding whether to leave Ghost at all, read Astro vs Ghost for publishing first: Ghost’s memberships and newsletters don’t come with you.
Key Takeaways
- Ghost’s Content API returns every published post with HTML, tags, authors and dates. A short script turns them into Markdown files.
- Ghost serves posts at the site root (
/my-post/), so an Astro[slug].astroroute at the root keeps URLs identical.- Images live under
/content/images/on your Ghost server. Download them before you shut Ghost down.- Export members as CSV and import them into your email provider; paid subscriptions need separate handling in Stripe.
- Redirect
/rss/to your new feed so subscribers’ readers keep working.
Before you start: decide what to keep
Write down what Ghost does for you today:
| Ghost feature | Astro replacement |
|---|---|
| Posts and pages | Markdown or MDX in content collections |
| Tags and authors | Frontmatter fields plus generated tag and author pages |
| Editor | Markdown files, or a headless CMS |
RSS at /rss/ |
@astrojs/rss endpoint |
| Members and newsletters | An email provider (Buttondown, Kit, Mailchimp, etc.) |
| Paid subscriptions | Stripe plus a membership service, or keep Ghost for that |
| Comments | A third-party comment service, if you used Ghost comments |
| Search | Pagefind or a hosted search |
If paid memberships are central, consider keeping Ghost as a headless CMS behind an Astro front end instead of a full migration.
Step 1: Create the Astro project and collection
npm create astro@latest my-blog
cd my-blog
npm install turndown
Define a collection that matches the fields you’ll export:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
description: z.string().default(''),
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
tags: z.array(z.string()).default([]),
author: z.string().default(''),
image: z.string().optional(),
}),
});
export const collections = { blog };
The Content Collections docs explain schemas and loaders in more detail.
Step 2: Export posts from Ghost
In Ghost Admin, create a custom integration (Settings, then Integrations) and copy the Content API key. The script below fetches every post, converts the HTML to Markdown with Turndown, and writes one file per post:
// scripts/ghost-export.mjs
import { mkdirSync, writeFileSync } from 'node:fs';
import TurndownService from 'turndown';
const GHOST_URL = process.env.GHOST_URL; // e.g. https://blog.example.com
const KEY = process.env.GHOST_CONTENT_KEY;
const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' });
const url = new URL('/ghost/api/content/posts/', GHOST_URL);
url.searchParams.set('key', KEY);
url.searchParams.set('limit', 'all');
url.searchParams.set('include', 'tags,authors');
url.searchParams.set('formats', 'html');
const { posts } = await (await fetch(url)).json();
mkdirSync('src/content/blog', { recursive: true });
const yaml = (s) => JSON.stringify(s ?? '');
for (const p of posts) {
const fm = [
'---',
`title: ${yaml(p.title)}`,
`description: ${yaml(p.custom_excerpt || p.excerpt?.slice(0, 155))}`,
`pubDate: ${p.published_at}`,
`updatedDate: ${p.updated_at}`,
`tags: ${JSON.stringify(p.tags.map((t) => t.name))}`,
`author: ${yaml(p.primary_author?.name)}`,
p.feature_image ? `image: ${yaml(p.feature_image)}` : null,
'---',
].filter(Boolean).join('\n');
writeFileSync(`src/content/blog/${p.slug}.md`, `${fm}\n\n${turndown.turndown(p.html ?? '')}\n`);
}
console.log(`Exported ${posts.length} posts`);
Run it with GHOST_URL=... GHOST_CONTENT_KEY=... node scripts/ghost-export.mjs. Repeat with the /pages/ endpoint for static pages like About.
Alternatively, use Ghost’s full JSON export (Settings, then Labs or Migration, then Export). It includes drafts and settings too, but needs more parsing.
Step 3: Clean up Ghost cards
Ghost’s editor produces cards (bookmarks, galleries, callouts, toggles, embeds) as HTML with kg- classes. Turndown converts the basics, but check these by hand or with extra Turndown rules:
- Bookmark cards become a mess of nested links. Replace them with a plain link or a small Astro component.
- Galleries become a run of images. That’s usually fine; wrap them in a grid component if you want the layout back.
- Callouts and toggles can become blockquotes or HTML
<details>elements. - Embeds (YouTube, X) arrive as iframes. Keep them as raw HTML in Markdown, or move the post to
.mdxand use a component.
Search the output for kg- to find leftovers:
grep -l "kg-" src/content/blog/*.md
Step 4: Download images
Ghost stores uploads at /content/images/YYYY/MM/file.jpg on your Ghost domain. If those URLs stay in your Markdown, they break the day Ghost goes offline. Download them into the project and rewrite the paths:
// scripts/ghost-images.mjs
import { readFileSync, writeFileSync, mkdirSync, globSync } from 'node:fs';
import { dirname } from 'node:path';
const pattern = /https?:\/\/[^)"'\s]+\/content\/images\/[^)"'\s]+/g;
for (const file of globSync('src/content/blog/*.md')) {
let text = readFileSync(file, 'utf8');
for (const src of new Set(text.match(pattern) ?? [])) {
const local = 'public/images/' + src.split('/content/images/')[1];
mkdirSync(dirname(local), { recursive: true });
writeFileSync(local, Buffer.from(await (await fetch(src)).arrayBuffer()));
text = text.replaceAll(src, local.replace('public', ''));
}
writeFileSync(file, text);
}
This puts images in public/images/ with their original folder structure. For build-time optimisation, move them next to the posts and reference them with relative paths instead, so Astro processes them; see the Astro image component guide.
Step 5: Keep Ghost’s URLs
Ghost’s default routes are:
- Posts:
/post-slug/at the root - Tags:
/tag/tag-slug/ - Authors:
/author/author-slug/ - RSS:
/rss/
Match the post route with a root-level dynamic page:
---
// src/pages/[slug].astro
import { getCollection, render } from 'astro:content';
import BaseLayout from '../layouts/BaseLayout.astro';
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({ params: { slug: post.id }, props: { post } }));
}
const { post } = Astro.props;
const { Content } = await render(post);
---
<BaseLayout title={post.data.title} description={post.data.description}>
<article>
<h1>{post.data.title}</h1>
<time datetime={post.data.pubDate.toISOString()}>{post.data.pubDate.toLocaleDateString('en-US')}</time>
<Content />
</article>
</BaseLayout>
Add src/pages/tag/[tag].astro the same way, generating one path per unique tag slug. The tags and categories guide has the full pattern. Static pages like about.astro take priority over [slug].astro, so they won’t clash.
If you used custom routes.yaml collections in Ghost (for example posts under /blog/), mirror that folder structure in src/pages/ instead.
Step 6: RSS, redirects and SEO
Create the feed with @astrojs/rss at src/pages/rss.xml.js; the RSS docs show the setup. Then redirect Ghost’s old feed path so feed readers keep working:
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
site: 'https://blog.example.com',
trailingSlash: 'always',
redirects: {
'/rss': '/rss.xml',
},
});
A host-level 301 (in _redirects on Netlify or Cloudflare Pages) is better for feeds than Astro’s build-time redirect page, since some feed readers don’t follow HTML meta refreshes. Also carry over each post’s meta title, meta description and canonical URL if you set them in Ghost (they’re in the API response as meta_title, meta_description and canonical_url).
Step 7: Members and newsletters
In Ghost Admin, go to Members and export all members as CSV. The file includes email, name, labels and subscription status. Import free subscribers into your new email provider, respecting each member’s subscribed status.
Paid members are harder. Their subscriptions live in your Stripe account, connected to Ghost. Moving them means setting up billing in the new tool and telling subscribers what changes. Plan this carefully, or keep Ghost running for memberships only.
Add a signup form to the new site; the newsletter signup tip shows a no-JavaScript version.
Step 8: Launch
- Build and preview locally:
npm run build && npx astro preview. - Spot-check 20 old URLs, including tags and the feed.
- Deploy to a static host and connect the domain.
- Submit the new sitemap in Google Search Console.
- Keep the Ghost install (or a backup) for a few weeks in case something was missed.
If you’d rather not design the new blog from scratch, Astro themes in the Blog & Editorial category come with post layouts, tag pages and RSS ready to receive your Markdown.
FAQ
How do I export posts from Ghost?
Use the Content API with a custom integration key to fetch posts as JSON with HTML bodies, or export the full site as JSON from Ghost Admin. Either way, convert the HTML to Markdown with a tool like Turndown before loading it into Astro.
Will I lose SEO moving from Ghost to Astro?
Not if URLs stay the same. Ghost serves posts at the site root, which an Astro [slug].astro page reproduces exactly. Redirect anything that changes with a 301, carry over meta titles and descriptions, and submit the new sitemap.
Can I keep my Ghost newsletter subscribers?
Yes. Export members as CSV from Ghost Admin and import them into your new email provider. Free subscribers move easily; paid subscriptions billed through Stripe need a separate plan.
What happens to Ghost images after migration?
They stay on your Ghost server until it shuts down. Download every image under /content/images/ into your Astro project and rewrite the paths before you turn Ghost off.
Can I use Ghost and Astro together instead?
Yes. Keep Ghost as a headless CMS and fetch posts into Astro at build time with the Content API. Writers keep Ghost’s editor, but Ghost’s member features won’t work on the Astro front end without extra work.