To move a Substack archive to Astro, create an export from your Substack settings, convert the HTML files in its posts/ folder to Markdown using the titles and dates from posts.csv, and publish them as an Astro content collection. If your Substack ran on a custom domain, serve the posts at the same /p/post-slug paths so every old link keeps working. Your subscriber list comes in the same export, ready to import into whichever email tool sends your newsletter next.
This guide is for writers who want the archive on a fast site they own. It covers the Substack to Astro conversion with working scripts, plus the decisions around paid posts and subscribers.
Key Takeaways
- Substack’s export gives you
posts.csv(metadata), aposts/folder of HTML bodies, and a subscriber CSV.- A Node.js script joins the CSV and HTML and writes Markdown files with frontmatter.
- Substack post URLs look like
/p/post-slug. On a custom domain, an Astrosrc/pages/p/[slug].astroroute keeps them identical.- On a
substack.comsubdomain you can’t redirect, so link from the old publication instead.- Decide what to do with paid-only posts before you publish them on an open site.
What the Substack export contains
In your Substack dashboard, open Settings, find the export section, and create a new export. Substack prepares a zip file you can download. Inside you’ll find:
| File | Contents |
|---|---|
posts.csv |
One row per post: ID and slug, date, title, subtitle, whether it’s published, and audience (everyone or paid) |
posts/ |
One HTML file per post, holding the post body only |
| Email list CSV | Subscribers with email, subscription status and dates |
The HTML files are named after the post ID and slug, which matches the post_id column in posts.csv. That’s how you join a body to its title and date. Open the CSV first to confirm column names in your export, as Substack has adjusted them over time.
Step 1: Set up the Astro project
npm create astro@latest my-newsletter
cd my-newsletter
npm install turndown csv-parse
Define a collection that keeps the audience field, so you can decide later how to treat paid posts:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const posts = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/posts' }),
schema: z.object({
title: z.string(),
subtitle: z.string().default(''),
pubDate: z.coerce.date(),
audience: z.string().default('everyone'),
}),
});
export const collections = { posts };
Step 2: Convert the archive to Markdown
Unzip the export into substack-export/, then run:
// scripts/substack-import.mjs
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
import { parse } from 'csv-parse/sync';
import TurndownService from 'turndown';
const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' });
const rows = parse(readFileSync('substack-export/posts.csv'), { columns: true, skip_empty_lines: true });
mkdirSync('src/content/posts', { recursive: true });
let count = 0;
for (const row of rows) {
if (row.is_published !== 'true') continue;
const file = `substack-export/posts/${row.post_id}.html`;
if (!existsSync(file)) continue;
const slug = row.post_id.split('.').slice(1).join('.');
const fm = [
'---',
`title: ${JSON.stringify(row.title)}`,
`subtitle: ${JSON.stringify(row.subtitle ?? '')}`,
`pubDate: ${row.post_date}`,
`audience: ${JSON.stringify(row.audience || 'everyone')}`,
'---',
].join('\n');
const md = turndown.turndown(readFileSync(file, 'utf8'));
writeFileSync(`src/content/posts/${slug}.md`, `${fm}\n\n${md}\n`);
count++;
}
console.log(`Imported ${count} posts`);
Run node scripts/substack-import.mjs. Unpublished drafts are skipped. Check a handful of posts against the live versions, especially ones with footnotes, embedded tweets or buttons.
Step 3: Clean up Substack-specific markup
Substack bodies include a few elements that don’t make sense on your own site:
- Subscribe and share buttons convert to plain links pointing at your Substack. Remove them, or replace them with a signup link to your new list.
- Captioned images come through as images followed by caption text. That’s usually fine.
- Embedded posts and tweets become links. Keep the link with a short quote.
- Footnotes may arrive as numbered links to anchors. Convert them to Markdown footnotes (
[^1]) if you want Astro to render them properly; GitHub-flavored Markdown footnotes are supported by default.
Search for leftovers:
grep -l "substack.com/subscribe\|button-wrapper" src/content/posts/*.md
Step 4: Save images locally
Substack images are hosted on its CDN (substackcdn.com, often wrapped in an image proxy URL). Download them so your archive doesn’t depend on Substack:
// scripts/substack-images.mjs
import { readFileSync, writeFileSync, mkdirSync, globSync } from 'node:fs';
import { createHash } from 'node:crypto';
mkdirSync('public/images/posts', { recursive: true });
const pattern = /https:\/\/[^)\s"]*substack[^)\s"]*\.(?:png|jpe?g|gif|webp)[^)\s"]*/gi;
for (const file of globSync('src/content/posts/*.md')) {
let text = readFileSync(file, 'utf8');
for (const src of new Set(text.match(pattern) ?? [])) {
const ext = src.match(/\.(png|jpe?g|gif|webp)/i)[1].toLowerCase();
const name = createHash('sha1').update(src).digest('hex').slice(0, 12) + '.' + ext;
const res = await fetch(src);
writeFileSync(`public/images/posts/${name}`, Buffer.from(await res.arrayBuffer()));
text = text.replaceAll(src, `/images/posts/${name}`);
}
writeFileSync(file, text);
}
Hashed file names avoid collisions between images that share a name. Review alt text while you’re at it; Substack exports often leave it empty.
Step 5: Keep the /p/ URLs
Substack serves posts at /p/post-slug. If your publication used a custom domain, you’ll move that domain to the new host, and an Astro route at the same path keeps every link, search result and share working:
---
// src/pages/p/[slug].astro
import { getCollection, render } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';
export async function getStaticPaths() {
const posts = await getCollection('posts');
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.subtitle}>
<article>
<h1>{post.data.title}</h1>
{post.data.subtitle && <p class="subtitle">{post.data.subtitle}</p>}
<Content />
</article>
</BaseLayout>
Add an archive page at src/pages/archive.astro that lists posts by date, and an RSS feed. The RSS feed guide shows the @astrojs/rss setup. Substack’s own feed lived at /feed, so redirect /feed to your new feed with a host-level 301.
If your publication was on yourname.substack.com, Substack controls that subdomain and you can’t redirect it. Use a final post announcing the move and update your publication’s about page with the new address.
Step 6: Decide what to do with paid posts
Posts with a paid audience were behind Substack’s paywall. Publishing them on an open static site makes them free. Options:
- Make the archive free. Simple, good for discovery, and fine if paid value comes from new posts.
- Publish only free posts. Filter in
getStaticPaths()withgetCollection('posts', ({ data }) => data.audience === 'everyone'). - Gate them on a membership platform. Keep paid posts on a service that handles subscriptions, and link to it.
A static Astro site has no login, so true paywalls need a separate service or server-rendered routes with authentication.
Step 7: Move subscribers
Import the subscriber CSV into your next email tool (Buttondown, Kit, Ghost, Beehiiv and others accept CSV imports). Keep only subscribers with an active status, and send a short note explaining the move so nobody is surprised by a new sender address.
Paid subscriptions billed through your Stripe account need a separate plan. Some newsletter platforms offer to migrate Stripe subscriptions; check with the one you choose before cancelling anything on Substack.
On the Astro site, add a signup form that posts to your new provider. The newsletter signup tip has a no-JavaScript version.
Launch checklist
- Archive builds, and post count matches
posts.csv. - Images load from your own domain.
/p/URLs and/feedwork on the custom domain.- Paid posts handled as decided.
- Subscribers imported and notified.
- Sitemap submitted in Search Console.
For a reading-focused design, Astro themes in the Blog & Editorial category include archive pages and post layouts suited to newsletter writing.
FAQ
How do I export my Substack posts?
In your Substack dashboard, open Settings, find the export section and create a new export. The zip contains posts.csv with metadata, a posts/ folder of HTML post bodies, and a CSV of your subscribers.
Can I keep my Substack URLs after moving to Astro?
Yes, if you used a custom domain. Move the domain to your new host and create an Astro route at src/pages/p/[slug].astro, so posts keep their /p/post-slug paths. A substack.com subdomain can’t be redirected.
Can I take my Substack subscribers with me?
Yes. The export includes a subscriber CSV you can import into another email provider. Paid subscriptions run through your Stripe account and need a separate migration plan with the new platform.
Does Astro send newsletters?
No. Astro builds the website and archive. Sending email needs a newsletter service; your Astro site can host the signup form and the public archive of past issues.
What happens to paid-only posts?
They become public if you publish them on a static Astro site. Filter them out by audience, make the archive free on purpose, or keep paid content on a membership platform.