Migrating from Jekyll to Astro.js is shockingly easy. You won’t regret it.
Jekyll has been my goto framework when working with static-site generators, and for years I had no issues at all. I loved the level of automation, the easy to learn Liquid template language and the flexibility. In the last two years following the upgrade to a Mac M1, however, the number of problems increased, and they have been increasingly difficult to solve. The issues has not been with Jekyll itself, but with Ruby, some selected Jekyll third party plugins and their incompatibility with different versions of Ruby. With every update of MacOS and Mac’s command line tools, I had to reinstall or upgrade Ruby, the plugins and the libraries needed by my project. A tiresome process taking away the focus on creating content. I used Ruby Version Manager to solve the discrepancy between Mac’s older version of Ruby and the actual newest stable release of Ruby. Getting Ruby working, I too often found myself fighting with Jekyll’s plugins, and after numerous cryptic error messages and endless build errors I just had enough. I had to find a better way forward.
Astro.js is a modern web framework designed for building fast, content-focused websites using any frontend framework or no framework at all. I did consider alternatives, like Next.js, but I wanted to be vendor and UI-library independent. Astro.js being a part of the rich JavaScript ecosystem means huge advantages and flexibility. Furthermore, Astro.js has support for Markdown files with YAML-frontmatter, making me able to copy over the content from my old Jekyll-site directly over to Astro.js with almost no change at all. Amazing!
First, head over to the Astro.js migration guide
npm create astro@latest -- --template blog
npm run astro add typescript
and npm run astro add react
. public
folder and stylesheets to styles
folder. I use SASS and Astro makes a very good job preprocessing, compressing and embedding the stylesheet into the build. You can also use CSS-modules or any other way of styling you prefer.content
folder, code the schemas representing your YAML front-matter for your blogs. This is optional, but when using TypeScript it will save you from a lot of type checking hassle.content/blog
folderpages
folder with .astro
, .md
, .mdx
or .html
files. At this step you will need to rewrite older Jekyll Liquid code to Astro and React code. More importantly, Astro does not use permalinks, so you will need to think about how you want route your pages. See Astro routing guide for more info.During the process I rewrote
The reason I did it like this, is because it makes future migration easier. Astro-components can make use of built-in Astro-functions, while the reusable React-components hold the essential UI-constructions that make up my site. I use Astro-components only for layout-specific setup and layout-specific root pages on certain routes that I can’t, and likely won’t, migrate later.
Making a pagination component in Astro is extremely simple and easy. However, figuring out the correct typing with TypeScript can be challenging. Here is the code and the correct typing I use on this site.
You can then use this component in a dynamic page called [page.astro]:
This will produce, with the stylesheet used on this site, to this:
I experienced some minor issues within IntelliJ while migrating my code. It’s small things that are worth paying the price for, rather than troubleshooting Ruby:
Learning and using Astro.js has so far been a great experience, and I can finally focus on my content again rather than debugging Ruby. I really like the default config of Astro, as it is tuned by default to generate a complete static-site output with correct routing.