Jamstack on .NET : how I built this site
Posted 17 May 2021
It's taken way longer than I had hoped to move this site to a new platform. About 2 years ago I read about static site generation and the buzz around JAMStack. Back in 2018 while working at TrueLime I got to witness the unveiling of Kentico's headless CMS: Kontent or, rather, Kentico Cloud as it was called back then. All this definitely peaked my interest so I set off on a journey to learn about the JAMStack ecosystem.
The Goals
I set out to rebuild this site using JAMStack principals and a couple of goals of my own:
- I want to own my content
- I like fast sites
- I need to be able to render my content as I see fit, using whatever tech I like
- The stack should not be too much of a hassle to maintain
- It should be super easy to publish a new post
- I'm Dutch so it shouldn't cost me much 😎
- I don't want to reinvent the wheel (not too much, anyway 😋 )
Adventures in Jamstack
JAMStack is all about standing on the shoulders of giants. Recombine stuff that is out there into something new by pulling in data from APIs and orchestrating the transformation of content across services.
I started out with the defacto king of JAMStack; Gatsby. It combines React, server side rendering and GraphQL into a top-notch dynamic web platform. There was a lot of buzz around Gatsby in 2019 and 2020 and I had done some React work already so it seemed like a decent fit. Being a primarily .NET backend developer though, I found the knowledge gap was too big for me. In addition to that the whole Progressive Web App paradigm seemed like overkill for what I was trying to achieve; build my personal site.
I looked at some of the other major players in the JAMStack ecosystem: Hugo and Jekyll. I learned a lot about how they do things but found their paradigm too constraining. And... I really don't enjoy mucking about with Handlebars.
Static site generation on .NET
Obviously I did some scouting into the SSG landscape on .NET. But found no clear winner at the time.
In late 2019 I remembered there was some work in the Kentico community to use Kontent with .NET based static site generators (SSG), particularly Wyam. I played around with this back in 2018 and found the tooling was lacking some of the nice strong typed content features available in the .NET SDK for Kontent. Unfortunately the code I wrote to fix that was lost after switching jobs.
Since .NET is my home turf so I decided to pick up the project to try and see if I can integrate the Kontent Delivery SDK for .NET with Wyam.
Wyam left me dazed and confused for a while. I pushed on though until I hit a nasty snag, tried to fix it but got no reply.
Wyam is dead! Long live Statiq!
It took me a while to catch on to the fact that Wyam had been forked into Statiq and all active development was focused on that. So I forked Kontent.Wyam (yet again) into Kontent.Statiq and found the same problem. This time around though, the PR was accepted 🎉.
Statiq is in many ways the better version of Wyam. It fixes much of the pain of getting started. There's still a steep learning curve though, especially coming from ASP.NET MVC style back-end driven web applications.
Thing that really needs to sink in is that static site generation is a very different paradigm. It's about pipelining content transformations as opposed to ASP.NET MVC, which is about serving single requests.
The fun thing about Statiq though is that it's such a generic solution that you can pipeline pretty much anything, including the build process for the tool itself. That means you can get it to do just about anything that happens in a front-end pipeline, all from the comfort of .NET.
Statiq comes in two parts; Statiq Framework is the core and Statiq Web is layered on top of that to provide functionality similar to the likes of Jekyll and Hugo. In my projects I tend to cherry pick the cool hosting features from Statiq Web but build most of the pipelines myself.
Working with Kentico Kontent
By the time I had published the first beta releases Kontent.Statiq, the folks at Kentico got in touch, looking to collaborate. I obviously accepted the offer and we got together with Dave Glick, the master mind behind Statiq to further the integration between the tools.
The developer relations folks at Kentico gave quite a boost to the idea of JAMStack on .NET. I'm very much convinced that there is a huge potential among .NET devs to extend the JAMStack landscape and include even more tools and techniques.
To verify that my project was up to the job, I started converting a couple of JAMStack templates to Kontent and Statiq.
The Memoirs theme is a blog theme that has a front-end search feature based on lunr.js. It's a nice demonstration of what static site generation on .NET Core can do.
Next up was an e-commerce template. I took the Snipcart Planty template and plugged that into Kontent. It all works beautifully and goes even further to demonstrate that a headless CMS can actually drive an e-commerce site on top of .NET Core.
And finally... build my own site
Like I said, I did not want to invent the wheel (too much) and stuck to that by not writing my own blogging engine. I did however write pretty much everything else... a classic trap.
I'm quite pleased with the result though. On top of that I got to play with cool new stuff and I got to work with some great people and managed to build some nice open source projects. I'll share more details about what I learned in upcoming posts.