🔥 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

Jekyll to Astro Migration: Move Posts, Layouts and URLs

Migrate from Jekyll to Astro step by step: move _posts into a collection, convert Liquid layouts and includes to components, keep permalinks and deploy to GitHub Pages.

#Astro#Jekyll#Migration#GitHub Pages#Jekyll to Astro

To migrate from Jekyll to Astro, copy _posts/ into an Astro content collection, define a schema for your YAML front matter, rewrite _layouts/ as Astro layouts and _includes/ as components, replace Liquid tags with JavaScript expressions, and rebuild Jekyll’s permalink pattern in getStaticPaths() so every URL stays the same. Then add @astrojs/rss and @astrojs/sitemap in place of jekyll-feed and jekyll-sitemap, and deploy with the withastro/action workflow if you host on GitHub Pages.

Jekyll and Astro share a lot: Markdown posts, YAML front matter, layouts and static output. A Jekyll to Astro migration is mostly a translation of templates, with no changes to the writing itself. The Astro vs Jekyll comparison covers whether the move is worth it for your site.

Key Takeaways

  • Posts and YAML front matter move over unchanged. Liquid inside posts needs replacing.
  • _layouts/ become Astro layouts with <slot />; _includes/ become components with props.
  • The date in YYYY-MM-DD-title.md filenames is not parsed automatically. Read it in your route code.
  • Jekyll’s default permalinks end in .html. Use build.format: 'file' or redirects to keep them.
  • GitHub Pages deploys Astro through a GitHub Actions workflow instead of its built-in Jekyll build.

Concept map: Jekyll to Astro

Jekyll Astro
_config.yml astro.config.mjs
_posts/2024-05-14-hello.md src/content/posts/2024-05-14-hello.md
_layouts/default.html src/layouts/Base.astro
_layouts/post.html src/layouts/Post.astro or the route file
_includes/header.html src/components/Header.astro
{{ page.title }} {post.data.title}
{% for post in site.posts %} posts.map((post) => ...)
{% include x.html param=1 %} <X param={1} />
_data/*.yml JSON/YAML import or a file() loader collection
Collections in _config.yml Collections in src/content.config.ts
jekyll-feed @astrojs/rss
jekyll-sitemap @astrojs/sitemap
jekyll-seo-tag A <head> component in your layout
jekyll-redirect-from redirects in astro.config.mjs
assets/, root static files public/ (or src/assets/ for optimised images)

Step 1: Create the project

npm create astro@latest my-site-astro
cd my-site-astro
npx astro add mdx sitemap
npm install @astrojs/rss

Copy assets/, images/, favicon.ico, CNAME and other static files into public/. If you used Sass, install sass and import your stylesheets from a layout; the Sass setup tip covers it.

Step 2: Move posts into a collection

Copy _posts/*.md into src/content/posts/ and define a schema matching your front matter:

// 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,mdx}', base: './src/content/posts' }),
  schema: z.object({
    title: z.string(),
    date: z.coerce.date().optional(),
    categories: z.union([z.string(), z.array(z.string())]).optional(),
    tags: z.array(z.string()).default([]),
    excerpt: z.string().optional(),
    redirect_from: z.array(z.string()).default([]),
    published: z.boolean().default(true),
  }),
});

export const collections = { posts };

Jekyll reads the post date from the filename when front matter has none. Astro does not, so add a helper that falls back to the filename:

// src/lib/posts.ts
import type { CollectionEntry } from 'astro:content';

export function postDate(post: CollectionEntry<'posts'>): Date {
  if (post.data.date) return post.data.date;
  const m = post.id.match(/^(\d{4})-(\d{2})-(\d{2})-/);
  return m ? new Date(`${m[1]}-${m[2]}-${m[3]}T00:00:00Z`) : new Date(0);
}

export function postSlug(post: CollectionEntry<'posts'>): string {
  return post.id.replace(/^\d{4}-\d{2}-\d{2}-/, '');
}

categories in Jekyll can be a string or a list, which the schema above accepts. The content collections guide covers schemas in detail.

Step 3: Convert layouts and includes

A Jekyll post layout:

<!-- _layouts/post.html (Jekyll) -->
---
layout: default
---
<article>
  <h1>{{ page.title }}</h1>
  <time>{{ page.date | date: "%B %-d, %Y" }}</time>
  {{ content }}
  {% include share.html url=page.url %}
</article>

becomes a component that wraps a base layout:

---
// src/layouts/Post.astro
import Base from './Base.astro';
import Share from '../components/Share.astro';

interface Props { title: string; date: Date; description?: string }
const { title, date, description } = Astro.props;
---
<Base title={title} description={description}>
  <article>
    <h1>{title}</h1>
    <time datetime={date.toISOString()}>
      {date.toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric', timeZone: 'UTC' })}
    </time>
    <slot />
    <Share url={Astro.url.pathname} />
  </article>
</Base>

Common Liquid translations:

Liquid Astro
{{ content }} <slot /> in layouts, <Content /> for entries
{% if page.image %}...{% endif %} {image && (...)}
{% for p in site.posts limit:5 %} posts.slice(0, 5).map((p) => ...)
{{ site.title }} A constant in src/consts.ts
{{ x | relative_url }} import.meta.env.BASE_URL + path
{{ x | markdownify }} Render Markdown in a collection, or use a library like marked
{{ x | slugify }} A small slugify() helper

The Astro components guide covers props and slots.

Jekyll’s default permalink: date produces URLs like /news/2024/05/14/hello.html (categories, then date, then title, with .html). Many sites use permalink: pretty, which gives /news/2024/05/14/hello/. Find yours in _config.yml and reproduce it.

For pretty permalinks without categories (/:year/:month/:day/:title/):

---
// src/pages/[year]/[month]/[day]/[slug].astro
import { getCollection, render } from 'astro:content';
import Post from '../../../../layouts/Post.astro';
import { postDate, postSlug } from '../../../../lib/posts';

export async function getStaticPaths() {
  const posts = await getCollection('posts', ({ data }) => data.published);
  return posts.map((post) => {
    const d = postDate(post);
    return {
      params: {
        year: String(d.getUTCFullYear()),
        month: String(d.getUTCMonth() + 1).padStart(2, '0'),
        day: String(d.getUTCDate()).padStart(2, '0'),
        slug: postSlug(post),
      },
      props: { post, date: d },
    };
  });
}

const { post, date } = Astro.props;
const { Content } = await render(post);
---
<Post title={post.data.title} date={date} description={post.data.excerpt}>
  <Content />
</Post>

If your URLs end in .html, set build.format: 'file' in astro.config.mjs. Astro then writes hello.html instead of hello/index.html, matching Jekyll’s output. Also match trailing slash behaviour; the trailing slash tip explains the options.

Step 5: Index pages, pagination and data

Rebuild the home page list with getCollection('posts') sorted by postDate(). If you used jekyll-paginate, use Astro’s paginate() in a src/pages/page/[page].astro route to keep /page/2/ URLs.

Data in _data/ can be imported directly:

---
// src/components/Team.astro
import team from '../data/team.json';
---
<ul>{team.map((m) => <li>{m.name}, {m.role}</li>)}</ul>

Convert YAML data files to JSON, or load them as a collection with the file() loader, which parses YAML.

Step 6: Clean up Liquid inside posts

Search posts for {% and {{. Typical cases:

  • {% highlight js %}...{% endhighlight %} becomes a fenced code block with a language tag.
  • {% include youtube.html id="..." %} becomes an MDX component; rename the file to .mdx.
  • {{ site.baseurl }}/images/x.png becomes a plain path, or a relative path to an image in src/ for optimisation.
  • {% raw %} blocks can simply be removed.

Step 7: Feeds, sitemap, SEO and redirects

Create src/pages/feed.xml.ts with @astrojs/rss so the feed stays at /feed.xml, where jekyll-feed put it. Add sitemap() to integrations. Replace jekyll-seo-tag with a Head component that outputs title, description, canonical and Open Graph tags.

For redirect_from entries, build the redirects map from your posts at config time, or list them by hand:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
  site: 'https://example.github.io',
  integrations: [sitemap()],
  redirects: {
    '/old-post/': '/2024/05/14/hello/',
  },
});

The redirects tip covers static and host-level redirects.

Step 8: Deploy to GitHub Pages

GitHub Pages builds Jekyll automatically, but Astro needs a workflow. In the repository settings, set Pages to deploy from GitHub Actions, then add:

# .github/workflows/deploy.yml
name: Deploy to GitHub Pages
on:
  push:
    branches: [main]
permissions:
  contents: read
  pages: write
  id-token: write
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: withastro/action@v3
  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
    steps:
      - uses: actions/deploy-pages@v4

For a project site at username.github.io/repo/, set base: '/repo' in config. Keep CNAME in public/ for a custom domain. The static deployment docs cover other hosts.

Step 9: Verify

Compare Jekyll’s sitemap.xml with Astro’s output, check every URL, and test the feed. The official Jekyll migration guide has more mappings. If you want a new design at the same time, the Komal blog and editorial themes are full Astro 7 projects you can move your posts into.

FAQ

Can Astro use my Jekyll Markdown posts?

Yes. Markdown and YAML front matter work as-is. Replace Liquid tags inside posts with Markdown or MDX components, and read the date from the filename if your front matter has none.

Do Jekyll themes work in Astro?

No. Jekyll themes are Liquid templates. Recreate the design in Astro components, or start from an Astro theme.

How do I keep .html URLs from Jekyll in Astro?

Set build.format: 'file' so Astro writes page.html files, and build the same paths in getStaticPaths(). Alternatively, move to clean URLs and redirect the old .html paths.

Can I still host on GitHub Pages after moving to Astro?

Yes. Switch Pages to GitHub Actions and use the official withastro/action workflow. Set site, and base if the site lives under a repository path.

What replaces Jekyll plugins in Astro?

Official integrations cover the common ones: @astrojs/rss for feeds, @astrojs/sitemap for sitemaps, and redirects in config for redirect-from. SEO tags go in a layout component.