🔥 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

Hugo to Astro Migration: Step-by-Step Guide with Examples

Migrate from Hugo to Astro: convert front matter, map Go templates to components, rebuild sections, taxonomies and permalinks, replace shortcodes and keep aliases.

#Astro#Hugo#Migration#Static Site Generator#Hugo to Astro

To migrate from Hugo to Astro, move your content/ Markdown into Astro content collections (TOML and YAML front matter both work), rewrite Hugo’s layouts/ as Astro layouts and components, recreate sections, taxonomies and permalinks with dynamic routes and getStaticPaths(), replace shortcodes with MDX components, and turn front matter aliases into Astro redirects. Static files in static/ go into public/ unchanged.

Hugo to Astro migrations usually happen when a site outgrows Go templates: the team wants components, TypeScript, interactive widgets or a JavaScript ecosystem. Hugo is very fast and stable, so if build speed is your only concern, stay; the Astro vs Hugo comparison covers the trade-off.

Key Takeaways

  • Markdown content moves with little change. Astro reads TOML (+++) and YAML (---) front matter; only JSON front matter needs converting.
  • baseof.html, single.html and list.html become an Astro layout plus page templates in src/pages/.
  • Hugo partials map to Astro components with typed props.
  • Sections, taxonomies and pagination are explicit routes in Astro, written with getStaticPaths() and paginate().
  • Shortcodes become MDX components; aliases become entries in redirects.

Concept map: Hugo to Astro

Hugo Astro
hugo.toml / config.toml astro.config.mjs
content/posts/*.md src/content/posts/*.md in a collection
Front matter (TOML, YAML, JSON) YAML front matter validated by a schema (TOML +++ also works)
layouts/_default/baseof.html src/layouts/Base.astro
layouts/_default/single.html src/pages/posts/[...slug].astro
layouts/_default/list.html / _index.md src/pages/posts/index.astro
layouts/partials/*.html src/components/*.astro
Shortcodes MDX components
Taxonomies src/pages/tags/[tag].astro
.Paginate paginate() in getStaticPaths()
data/*.yaml JSON/YAML imports or a file() loader collection
static/ public/
assets/ with Hugo Pipes src/ assets processed by Vite
aliases in front matter redirects in astro.config.mjs
permalinks config Route file paths and params

Step 1: Create the project and copy static files

npm create astro@latest my-site-astro
cd my-site-astro
npx astro add mdx sitemap
npm install @astrojs/rss
cp -R ../my-hugo-site/static/. public/

Set site in astro.config.mjs to your production URL (Hugo’s baseURL). The Astro config docs cover the main options.

Step 2: Check front matter

Hugo accepts TOML front matter between +++ fences, YAML between ---, or JSON. Astro reads both TOML (+++) and YAML (---) front matter in Markdown, so most Hugo posts work without conversion:

+++
title = "Deploying on a budget"
date = 2024-05-14T09:00:00Z
tags = ["hosting", "static"]
draft = false
+++

Three things still need attention:

  1. JSON front matter (a { block at the top of the file) is Hugo-specific. Convert those files to YAML or TOML.
  2. Hugo-only fields such as weight, aliases, slug, url or type are just data to Astro. Add the ones you use to your schema and implement their behaviour yourself.
  3. Consistency. Teams that plan to edit content with a Git-based CMS often convert everything to YAML, because many CMS tools expect it. A short script with smol-toml and yaml from npm handles hundreds of files at once.

Step 3: Define collections

Map each Hugo section to a collection:

// 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}', '!**/_index.md'], base: './src/content/posts' }),
  schema: z.object({
    title: z.string(),
    date: z.coerce.date(),
    tags: z.array(z.string()).default([]),
    draft: z.boolean().default(false),
    aliases: z.array(z.string()).default([]),
    description: z.string().optional(),
  }),
});

export const collections = { posts };

The negated pattern skips Hugo’s _index.md section files. Move any content you need from them (a section intro, for example) into the list page itself. Page bundles (my-post/index.md with images beside it) work as-is, and their entry id becomes my-post.

Step 4: Rebuild layouts and partials

Hugo’s baseof.html with blocks:

<!-- layouts/_default/baseof.html (Hugo) -->
<html lang="{{ .Site.LanguageCode }}">
  <head>{{ partial "head.html" . }}</head>
  <body>
    {{ partial "header.html" . }}
    {{ block "main" . }}{{ end }}
    {{ partial "footer.html" . }}
  </body>
</html>

becomes an Astro layout where <slot /> replaces the block:

---
// src/layouts/Base.astro
import Head from '../components/Head.astro';
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';

interface Props { title: string; description?: string }
const { title, description } = Astro.props;
---
<html lang="en">
  <head><Head title={title} description={description} /></head>
  <body>
    <Header />
    <slot />
    <Footer />
  </body>
</html>

Template logic translates directly: {{ range }} becomes .map(), {{ if }} becomes a JavaScript condition, {{ .Title }} becomes {post.data.title}, and Hugo functions like dateFormat become toLocaleDateString() or a small helper. The Astro components guide covers props and slots.

Hugo’s permalinks setting decides URLs. Reproduce it with the route file and params. For posts = "/:year/:month/:slug/":

---
// src/pages/[year]/[month]/[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: {
      year: String(post.data.date.getUTCFullYear()),
      month: String(post.data.date.getUTCMonth() + 1).padStart(2, '0'),
      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>
    <Content />
  </article>
</Base>

If Hugo used the default /posts/my-post/, a single src/pages/posts/[slug].astro is enough. If posts set a custom slug or url in front matter, read that field when building params. Hugo outputs trailing-slash URLs by default, so set trailingSlash: 'always' in Astro if you want identical URLs; see the trailing slash tip.

Step 6: Lists, taxonomies and pagination

Hugo generates section lists and taxonomy pages automatically. In Astro they are explicit, which takes a few more lines and gives full control:

---
// src/pages/tags/[tag]/[...page].astro
import type { GetStaticPaths } from 'astro';
import { getCollection } from 'astro:content';
import Base from '../../../layouts/Base.astro';

export const getStaticPaths = (async ({ paginate }) => {
  const posts = await getCollection('posts', ({ data }) => !data.draft);
  const tags = [...new Set(posts.flatMap((p) => p.data.tags))];
  return tags.flatMap((tag) =>
    paginate(
      posts.filter((p) => p.data.tags.includes(tag)).sort((a, b) => +b.data.date - +a.data.date),
      { params: { tag }, pageSize: 10 },
    ),
  );
}) satisfies GetStaticPaths;

const { page } = Astro.props;
const { tag } = Astro.params;
---
<Base title={`Posts tagged ${tag}`}>
  <h1>Tagged: {tag}</h1>
  <ul>{page.data.map((p) => <li><a href={`/posts/${p.id}/`}>{p.data.title}</a></li>)}</ul>
  {page.url.prev && <a href={page.url.prev}>Newer</a>}
  {page.url.next && <a href={page.url.next}>Older</a>}
</Base>

Hugo’s default pagination path is /page/2/; Astro’s [...page] produces /tags/x/2/. If you want Hugo’s exact URLs, name the folder accordingly or add redirects.

Step 7: Shortcodes and data files

Find shortcodes by searching for {{< and {{%. Built-ins such as youtube, figure and highlight map to MDX components or plain Markdown. Rename affected files to .mdx and import a component:

---
title: "Launch video"
date: 2024-06-01
---
import YouTube from '../../components/YouTube.astro';

Here is the launch walkthrough.

<YouTube id="dQw4w9WgXcQ" />

Code fences with language tags replace highlight. Data files in data/ can be imported directly (import team from '../data/team.json') or loaded into a collection with the file() loader.

Step 8: Aliases, feeds and sitemap

Collect aliases from every post and add them to redirects:

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

export default defineConfig({
  site: 'https://example.com',
  trailingSlash: 'always',
  integrations: [sitemap()],
  redirects: {
    '/2019/old-post-name/': '/posts/new-post-name/',
  },
});

On static hosts, Astro writes HTML redirect pages; host-level _redirects files give true 301s. The redirects tip explains both. Recreate Hugo’s RSS at the same path (often /index.xml) with @astrojs/rss in src/pages/index.xml.ts.

Step 9: Verify

  1. Save Hugo’s sitemap.xml and compare it with Astro’s sitemap-index.xml output.
  2. Check every old URL returns 200 or redirects.
  3. Compare titles, descriptions and canonicals on the top pages.
  4. Test the feed in a reader.

The official Hugo migration guide covers more cases. For a fresh design to move content into, the Komal blog and editorial themes are complete Astro 7 projects.

FAQ

Can I reuse Hugo themes in Astro?

No. Hugo themes use Go templates, which Astro cannot run. Rebuild the theme’s layouts as Astro components, or start from an Astro theme with a similar design.

Do Hugo shortcodes work in Astro?

No. Replace them with MDX components or standard Markdown. Most built-in shortcodes have simple equivalents.

How do I keep Hugo’s URLs in Astro?

Recreate your permalinks pattern with route folders and params in getStaticPaths(), set trailingSlash: 'always', and add redirects for every aliases entry.

Is Astro slower to build than Hugo?

Usually yes for very large sites, because Hugo is a compiled Go binary. For typical blogs and marketing sites, Astro builds in seconds to a few minutes, and the content layer cache skips unchanged entries.

Can Astro read TOML front matter?

Yes. Astro parses TOML front matter between +++ fences as well as YAML between ---, so Hugo posts using TOML can move without conversion. JSON front matter is not supported and needs converting.