Stop Building Your Own SSG: Lessons from Migrating to Astro
As painful as it is for me to say it…
My handmade custom static site generator was definitely not the way to go for a multi-purpose site.
Sure, as awesome as it is to craft everything yourself, the time came to draw the line while I was trying to build a new homepage. In my experience, crafting a janky custom generator specifically for a blog means your code will never naturally fit non-blog pages. It just isn’t efficient. Not to mention, it becomes incredibly brittle when you try to add more and more revisions as time passes. It really isn’t maintainable in the long run.
Rust was a Lesson, not the Solution
There is no doubt in my mind that building a generator from scratch helped me learn a lot about Rust. But it eventually dawned on me: I am definitely not keen on duct-taping a comment section template into my existing mess, let alone performing the large-scale refactorings required to make it work. It’s a pain in the neck.
To state the obvious, in case it isn’t- I hate web development. But even with that mindset, things are so, so much easier with Astro.
It feels a lot like PHP but… “better”
I looked at Eleventy, but I didn’t like the gigantic configuration files you had to maintain or how difficult it seemed to add custom features. I’m not a fan of Jekyll either; in my experience, it just isn’t that expandable. There are likely other frameworks out there, but with Astro, I basically get to have my cake and eat it too. I liked my own generator because I got to engineer it, but it was too much engineering for something I don’t actually enjoy doing.
Astro’s templating engine is leagues ahead of my home-made one. The difference is that it’s actually an engine, not just a script replacing placeholders with the results of executing very long functions written in Rust. While writing the entire site in Rust taught me a lot, it was a poor long-term choice. My entire system was effectively a series of terribly written find and replace text operations used to autofill text into templates. Implementing a real templating system from scratch would have taken significantly more time than actually building the features I wanted for the site.
I’m not the biggest fan of JavaScript- which is probably the main reason I hate web development- but it is undeniably convenient to handle my static site logic with JS in Astro. The .astro files are a mix of JS and HTML paired with a great templating engine. You can import CSS files the same way you import components. Components can define custom DOM structures that take in parameters and evaluate them cleanly.
It’s incredibly intuitive. I don’t know if it’s the ultimate solution for long-term maintainability- you still have to keep track of your component architecture and props- but it’s certainly a better solution than my own.
Ultimately, Astro is a great blend between giving you control and taking just enough of it away to keep you productive.