🔥 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

Eleventy to Astro Migration: Templates, Data and Collections

Migrate from Eleventy to Astro: convert Nunjucks or Liquid layouts to components, tag collections to content collections, global data, pagination and filters.

#Astro#Eleventy#11ty#Migration#Eleventy to Astro

To migrate from Eleventy to Astro, move your Markdown into Astro content collections, rewrite the layouts in _includes/ as Astro layouts and components, replace tag-based and addCollection() collections with getCollection() queries, turn _data/ files into imports or loaders, and rebuild front matter permalink and pagination as file routes with getStaticPaths() and paginate(). Filters and shortcodes become plain JavaScript functions and MDX components.

Eleventy and Astro share a philosophy: static HTML first, no client JavaScript unless you add it. That makes an Eleventy to Astro migration mostly a change of template language. Teams usually move for components with typed props, schema-validated content, built-in image optimisation and UI framework islands. The Astro vs Eleventy comparison covers the trade-offs.

Key Takeaways

  • Markdown and YAML front matter move over as-is; Nunjucks or Liquid inside Markdown needs replacing.
  • Eleventy layouts and includes become .astro components with <slot /> and props.
  • Tag-based collections become content collections filtered by a tags field.
  • JavaScript data files in _data/ become modules you import, or content loaders.
  • Front matter permalink and pagination become route files and getStaticPaths().

Concept map: Eleventy to Astro

Eleventy Astro
eleventy.config.js astro.config.mjs
src/posts/*.md src/content/posts/*.md in a collection
_includes/layouts/base.njk src/layouts/Base.astro
_includes/partials/*.njk src/components/*.astro
layout: post.njk in front matter Page imports and wraps a layout
tags: posts collections getCollection('posts')
addCollection() A function that filters and sorts getCollection() results
_data/site.json src/data/site.json imported where needed
_data/*.js that fetch APIs await fetch() in frontmatter, or a content loader
permalink: in front matter File path in src/pages/
pagination: in front matter paginate() in getStaticPaths()
addFilter() Exported JavaScript function
addShortcode() Astro component (in MDX for content)
addPassthroughCopy() public/
@11ty/eleventy-img <Image /> / <Picture /> from astro:assets
@11ty/eleventy-plugin-rss @astrojs/rss

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

Move everything you passed through with addPassthroughCopy() (fonts, favicons, robots.txt) into public/. Images you want optimised go in src/assets/ instead. Set site in astro.config.mjs.

Step 2: Move content into collections

Eleventy often uses a directory data file such as posts/posts.json with { "tags": "posts", "layout": "post.njk" } to apply settings to a folder. In Astro, the folder becomes a collection and those settings are no longer needed:

// 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(),
    description: z.string().optional(),
    tags: z.array(z.string()).default([]),
    draft: z.boolean().default(false),
  }),
});

export const collections = { posts };

Remove layout and permalink from post front matter, or leave them and ignore them; extra fields are stripped by the schema unless you list them. If posts use Eleventy’s special date: Last Modified or rely on the file date, set explicit dates before migrating. The content collections guide covers schemas and loaders.

Step 3: Convert layouts

An Eleventy base layout in Nunjucks:

{# _includes/layouts/base.njk (Eleventy) #}
<!doctype html>
<html lang="en">
  <head>
    <title>{{ title }} | {{ site.name }}</title>
    <meta name="description" content="{{ description or site.description }}">
  </head>
  <body>
    {% include "partials/header.njk" %}
    <main>{{ content | safe }}</main>
  </body>
</html>

becomes:

---
// src/layouts/Base.astro
import Header from '../components/Header.astro';
import site from '../data/site.json';

interface Props { title: string; description?: string }
const { title, description = site.description } = Astro.props;
---
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{title} | {site.name}</title>
    <meta name="description" content={description} />
  </head>
  <body>
    <Header />
    <main><slot /></main>
  </body>
</html>

Eleventy’s layout chaining (a post layout whose front matter says layout: base.njk) becomes composition: Post.astro renders <Base> around its own markup. The Astro components guide explains slots and props.

Step 4: Post pages and permalinks

Eleventy writes each Markdown file to a URL based on its path, or its permalink. In Astro, one dynamic route renders every post:

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

export async function getStaticPaths() {
  const posts = await getCollection('posts', ({ data }) => !data.draft);
  return posts.map((post) => ({ params: { slug: post.id }, props: { post } }));
}

const { post } = Astro.props;
const { Content } = await render(post);
---
<Base title={post.data.title} description={post.data.description}>
  <article>
    <h1>{post.data.title}</h1>
    <time datetime={post.data.date.toISOString()}>{post.data.date.toDateString()}</time>
    <Content />
  </article>
</Base>

If posts had custom permalinks, add a permalink field to the schema and use it for params (with a [...slug] rest route so it can contain slashes). Eleventy outputs /blog/my-post/index.html by default, which matches Astro’s default directory format.

Step 5: Collections, filters and sorting

Eleventy collections from addCollection():

// eleventy.config.js (Eleventy)
export default function (eleventyConfig) {
  eleventyConfig.addCollection('featured', (api) =>
    api.getFilteredByTag('posts').filter((p) => p.data.featured).sort((a, b) => b.date - a.date),
  );
  eleventyConfig.addFilter('readableDate', (d) => d.toLocaleDateString('en-US', { dateStyle: 'long' }));
}

become small helpers you import:

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

export async function getPublishedPosts() {
  const posts = await getCollection('posts', ({ data }) => !data.draft);
  return posts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
}

export const readableDate = (d: Date) => d.toLocaleDateString('en-US', { dateStyle: 'long' });

Because they are plain TypeScript, they are type-checked and reusable from any page or endpoint.

Step 6: Global data

Static files in _data/ (JSON or YAML) can be imported directly. JavaScript data files that fetch at build time translate to top-level await in the page that needs the data:

---
// src/pages/releases.astro
import Base from '../layouts/Base.astro';
const releases: { tag_name: string; name: string }[] = await fetch(
  'https://api.github.com/repos/withastro/astro/releases?per_page=5',
).then((r) => r.json());
---
<Base title="Releases">
  <ul>{releases.map((r) => <li>{r.tag_name}: {r.name}</li>)}</ul>
</Base>

If several pages need the same remote data, wrap the fetch in a content loader so it is fetched once per build and validated by a schema.

Step 7: Pagination and tag pages

Eleventy’s front matter pagination:

---
pagination:
  data: collections.posts
  size: 10
  alias: posts
permalink: "blog/{% if pagination.pageNumber > 0 %}page/{{ pagination.pageNumber + 1 }}/{% endif %}"
---

becomes:

---
// src/pages/blog/[...page].astro
import type { GetStaticPaths } from 'astro';
import Base from '../../layouts/Base.astro';
import { getPublishedPosts } from '../../lib/posts';

export const getStaticPaths = (async ({ paginate }) => {
  return paginate(await getPublishedPosts(), { pageSize: 10 });
}) satisfies GetStaticPaths;

const { page } = Astro.props;
---
<Base title="Blog">
  <ul>{page.data.map((p) => <li><a href={`/blog/${p.id}/`}>{p.data.title}</a></li>)}</ul>
  {page.url.next && <a href={page.url.next}>Older posts</a>}
</Base>

Astro’s URLs are /blog/, /blog/2/, /blog/3/. If you had /blog/page/2/, put the route at src/pages/blog/page/[page].astro for pages after the first, or add redirects. Tag pages follow the same pattern with a [tag] parameter. The pagination component guide builds the navigation.

Step 8: Shortcodes and images

Search Markdown for {% and {{. Shortcodes like {% image %} or {% youtube %} become MDX components; rename those files to .mdx and import the component. For images processed with @11ty/eleventy-img, use Astro’s <Image /> or <Picture />, and for plain Markdown images, relative paths are optimised automatically. The responsive images tip covers the options.

Step 9: Feed, sitemap and verification

Create src/pages/feed.xml.ts with @astrojs/rss at the same path as your old feed, add the sitemap integration, then compare URL lists from both builds. Every old URL should return 200 or redirect. The official Eleventy migration guide has further mappings.

If you are redesigning at the same time, starting from a finished Astro project can save effort; the Komal Astro themes are complete Astro 7 sites with content collections already set up.

FAQ

Is Astro similar to Eleventy?

Yes in output: both generate static HTML with no client JavaScript by default. Astro adds a component model, typed content collections, image optimisation, UI framework islands and optional server rendering.

Can I use Nunjucks templates in Astro?

No. Astro uses .astro components. Nunjucks and Liquid layouts need rewriting, which is usually a direct translation of loops and conditions into JavaScript expressions.

What replaces Eleventy’s global data files?

Import JSON or YAML files directly, use top-level await fetch() in frontmatter for remote data, or create a content loader when several pages share the same data.

How do Eleventy tags map to Astro?

Add a tags array to your collection schema and filter with getCollection('posts', ({ data }) => data.tags.includes('x')). Tag archive pages are dynamic routes built with getStaticPaths().

Will my Eleventy URLs stay the same?

They can. Eleventy’s default /path/index.html output matches Astro’s default directory format, so posts at /blog/my-post/ keep their URL when you use the same route structure.