🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Fundamentals••By Komal Nakrani

Medium to Astro: Move Your Blog to Your Own Site

Move a Medium blog to Astro: download your Medium archive, convert posts to Markdown, save images locally, publish on your domain and handle canonical links.

#Astro#Medium#Migration#Blog#Markdown

To move a Medium blog to Astro, download your account archive from Medium’s settings, convert the HTML files in its posts/ folder to Markdown, save the images locally, and load the posts into an Astro content collection on your own domain. Medium can’t redirect your old URLs, so point Medium’s copies at the new site with canonical links where you can, and link to your new home from your Medium profile.

The result is a blog you own: your domain, your design, no paywall in front of your readers, and pages that ship no JavaScript by default. This guide covers the full Medium to Astro move with scripts you can run.

Key Takeaways

  • Medium’s “Download your information” archive contains every post as an HTML file, plus drafts.
  • A short Node.js script with Cheerio and Turndown converts those files into Markdown with frontmatter.
  • Images stay on Medium’s CDN unless you download them; do that before you rely on the new site.
  • Medium URLs can’t be redirected, so use canonical links and profile links to send readers and search engines to your domain.
  • Followers don’t transfer. Collect emails on the new site from day one.

What moves and what doesn’t

Medium After the move
Published stories Markdown files in an Astro collection
Drafts Included in the archive (marked as drafts)
Images Downloaded into your project
Embeds (Gists, YouTube, tweets) Links or components you add back
Claps, highlights, responses Not exportable to your site
Followers Not transferable; build an email list
Medium URLs Stay on Medium; no redirects possible
Partner Program earnings Only on Medium

Many writers keep their Medium posts live and treat their own site as the main copy. That’s a reasonable approach, as long as the canonical link points to your domain.

Step 1: Download your Medium archive

On Medium, open Settings, then the Security and apps section, and choose “Download your information”. Medium emails a link to a .zip file. Inside, the posts/ folder holds one HTML file per story, named with the date and slug. Drafts are in the same folder, with names starting draft_.

Each file follows the h-entry microformat: the title has the class p-name, the body sits in an element with e-content, the publish date is a <time class="dt-published">, and the original URL is a link with p-canonical. That structure makes the files easy to parse.

Step 2: Set up the Astro blog

npm create astro@latest my-blog
cd my-blog
npm install cheerio turndown

Define the collection:

// 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(),
    mediumUrl: z.string().optional(),
    draft: z.boolean().default(false),
  }),
});

export const collections = { blog };

If you haven’t set up a blog in Astro before, building a blog with Astro covers layouts, listing pages and RSS.

Step 3: Convert posts to Markdown

Put the unzipped archive at medium-export/ in the project root, then run:

// scripts/medium-import.mjs
import { readFileSync, writeFileSync, readdirSync, mkdirSync } from 'node:fs';
import * as cheerio from 'cheerio';
import TurndownService from 'turndown';

const turndown = new TurndownService({ headingStyle: 'atx', codeBlockStyle: 'fenced' });
const dir = 'medium-export/posts';
mkdirSync('src/content/blog', { recursive: true });

for (const file of readdirSync(dir).filter((f) => f.endsWith('.html'))) {
  const $ = cheerio.load(readFileSync(`${dir}/${file}`, 'utf8'));
  const title = $('.p-name').first().text().trim();
  const subtitle = $('[data-field="subtitle"]').text().trim();
  const published = $('time.dt-published').attr('datetime');
  const mediumUrl = $('a.p-canonical').attr('href');
  const body = $('.e-content');
  body.find('h3').first().filter((_, el) => $(el).text().trim() === title).remove();

  const slug = file
    .replace(/^draft_/, '')
    .replace(/^\d{4}-\d{2}-\d{2}_/, '')
    .replace(/-[0-9a-f]{10,12}\.html$/, '')
    .toLowerCase();

  const fm = [
    '---',
    `title: ${JSON.stringify(title)}`,
    `description: ${JSON.stringify(subtitle)}`,
    `pubDate: ${published ?? new Date().toISOString()}`,
    mediumUrl ? `mediumUrl: ${JSON.stringify(mediumUrl)}` : null,
    `draft: ${file.startsWith('draft_')}`,
    '---',
  ].filter(Boolean).join('\n');

  writeFileSync(`src/content/blog/${slug}.md`, `${fm}\n\n${turndown.turndown(body.html() ?? '')}\n`);
}

Run node scripts/medium-import.mjs, then open a few files and compare them with the originals. Medium repeats the title as the first heading in the body, which the script removes. Adjust the slug logic if your file names look different, since the trailing ID format has varied over time.

Step 4: Fix code blocks and embeds

Medium’s code blocks have no language information, so Turndown writes plain fenced blocks. Add a language name after each opening fence (for example js or python) so Astro’s syntax highlighting works.

Embeds export as links or iframes. Common fixes:

  • GitHub Gists: paste the code into a fenced block instead. It’s faster to load and readable without JavaScript.
  • YouTube: keep the iframe, or switch the post to .mdx and use a lightweight embed component.
  • Tweets and other social embeds: a quote plus a link is often enough.

Search for leftovers with grep -l "iframe\|gist.github" src/content/blog/*.md.

Step 5: Download images

Medium images point to its CDN (miro.medium.com). Download them so your site doesn’t depend on Medium:

// scripts/medium-images.mjs
import { readFileSync, writeFileSync, mkdirSync, globSync } from 'node:fs';
import { basename } from 'node:path';

mkdirSync('public/images/blog', { recursive: true });
const pattern = /https:\/\/(?:miro|cdn-images-\d)\.medium\.com\/[^)\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 name = basename(new URL(src).pathname).replace(/[^\w.-]/g, '_');
    const res = await fetch(src);
    const ext = (res.headers.get('content-type') ?? 'image/jpeg').split('/')[1].replace('jpeg', 'jpg');
    const local = `/images/blog/${name}${name.includes('.') ? '' : '.' + ext}`;
    writeFileSync(`public${local}`, Buffer.from(await res.arrayBuffer()));
    text = text.replaceAll(src, local);
  }
  writeFileSync(file, text);
}

While you’re in each post, add meaningful alt text. Medium image captions often hold what the alt text should say.

Step 6: Publish on your domain

Build the post route and listing page, then deploy:

---
// src/pages/blog/[id].astro
import { getCollection, render } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';

export async function getStaticPaths() {
  const posts = await getCollection('blog', ({ data }) => !data.draft);
  return posts.map((post) => ({ params: { id: 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>
    <Content />
  </article>
</BaseLayout>

Deploy to Cloudflare Pages, Netlify, Vercel or GitHub Pages and connect your domain; the custom domain docs walk through DNS. Add an RSS feed so readers can follow you without Medium.

Since Medium won’t redirect, use these instead:

  1. Canonical links on Medium. Medium’s story settings let you mark a story as originally published elsewhere and set its canonical link. Point each one at the new URL so search engines treat your site as the original. Check the current location of this option in Medium’s help pages, as its settings menus change.
  2. Profile and bio links. Add your domain to your Medium bio and pin a story announcing the move.
  3. A closing line on each Medium story linking to the post on your site.
  4. An email signup on the new site. Medium followers aren’t yours to export, so give them a reason to subscribe directly.

For your own site’s search health, set site in astro.config.mjs, generate a sitemap, and submit it in Search Console. The Astro SEO checklist covers the rest.

If you want a polished blog design without building one, Astro themes in the Blog & Editorial category include post layouts, author pages and tag archives ready for your Markdown.

FAQ

How do I export my posts from Medium?

Go to Settings on Medium, open Security and apps, and choose “Download your information”. Medium emails you a zip file. Your stories and drafts are HTML files in its posts/ folder.

Can I redirect my Medium URLs to my own site?

No. You don’t control Medium’s servers, so you can’t add redirects. Instead, set canonical links on your Medium stories to point at the new URLs and link to your site from your profile and posts.

Should I delete my posts from Medium after moving?

Not necessarily. Keeping them with canonical links to your site lets you keep Medium readers while search engines credit your domain. Delete them only if you want a clean break.

Will my Medium followers move with me?

No. Medium doesn’t export follower emails. Announce the move in a story, add your domain to your bio, and offer an email signup on your new site.

Is Astro a good platform for a Medium writer?

Yes. Posts are Markdown files you own, pages load fast with no JavaScript by default, and hosting is usually free. You give up Medium’s built-in audience and Partner Program, so plan how readers will find you.