Dropping a simple blog into your .NET site with Pretzel

Published on Thursday, August 15, 2013

Photo by Jan Loyde Cabrera on Unsplash

One of the features I needed for EZReader was a very, very simple blog page for things like announcing new features. I wanted it function like a blog (with paging, an RSS feed, and discretely linkable articles), but I definitely did not want to deal with a full CMS or anything that required a separate database install. I wanted the additional load it created on the site to be minimal. And I wanted it to be hosted along with the actual website (as opposed to setting up separate hosting with, for example, Squarespace, and then point a subdomain at the blog host). This last one was partly for cost reasons and partly for look-and-feel reasons; if I made major site style changes I didn't want to have to maintain them in two places.

So my initial thought was to use Jekyll, the blog engine that GitHub uses for its generated pages. Rather than relying on a database to store posts and generating the pages on the fly, with Jekyll you generate the blog as a set of static HTML pages. There's a layout page (the basic look and feel) and each post is a separate file (written in Markdown, if you like, and I do), and whenever you add or update anything you regenerate the whole site. Since all you're serving is static HTML, you don't need any special handlers or a database to run your blog; it's pretty much the simplest possible deployment and hosting scenario imaginable.

Jekyll, though, is written in Ruby. And it's not officially supported on Windows. EZReader is all written on Windows machines, and uses .NET. I worked on getting a Jekyll site integrate with EZReader for a little while, but after the third or fourth hurdle it was becoming clear that this wasn't ideal. (Ruby on Windows is doable, but it takes some commitment to get everything up and running and it's pretty much always a second-class citizen. I think the only thing I've ever really used successfully was Rake.)

Luckily for me, there's an excellent project for .NET called Pretzel. It basically does the same thing as Jekyll but with native Windows tools. Even better, in addition to supporting Jekyll templates (you can take the source for a Jekyll site and produce the same output on Windows using pretzel), pretzel supports Razor, which is what I used for all the views in EZReader. So I was basically able to reuse my original site template for the blog portion of the site.

The source files (including each blog post) all live in my project under a folder call BlogTemplate; whenever I add a new post I pop open PowerShell and call pretzel bake to generate the static files. At some point I'll probably automate that step with TeamCity, but for now I'm enjoying how ridiculously simple this is.

It even generates RSS and ATOM feeds. Pretty sweet.