Ditching Wyam & making my own blog engine

Page Header
After moving from Ghost to Wyam, I was content with the way my blog was working, but something was still itching at the back of my mind.

The reason I didn’t go to another blogging platform from Ghost was because I wanted to experience creating my own blog engine, mostly as a way to develop my own skills. Using Wyam I felt ended up being too easy, I felt I hadn’t made it enough of a learning experience, so I started tinkering with a new ASP.NET MVC project.

I’ve been doing a lot more .NET dev work than normal over the past year, but the work I’ve done has been for large enterprise customers, and thus involves N-1 or N-2 versions of software (.NET 3.5, .NET 4.5, IIS 6, Java 6 & 7, even some webforms work sprinkled here and there). Whilst it’s rewarding work, it can be prudent to at least do some external projects to keep sharpening the saw on newer tools, as well as push yourself out of your comfort zone.

And now here it is. I built this blog application as an MVC app on .NET 4.6.2 (Core might be the next version), and have been trying to keep the codebase as simple as possible. The theming and everything is exactly the same as what I had with Wyam, but now I’m:

  • Generating the HTML from Markdown using CommonMark.NET. I like to write my posts in markdown, as writing markdown in VSCode is really nice with extensions.
  • Storing Metadata about each post in JSON at the start of the file and parsing it with Json.NET (this is opposed to Wyam’s YAML markup. I chose JSON because the parsing took less lines of code).
  • Caching the content on startup of the site, so there’s only a single read of the markdown into memory (+ a refresh every 24hrs).

The benefits I’ve found so far have been:

  • I can 1-click publish to Azure with this project, and I barely lifted a finger during configuration. Heaven.
  • Application Insights is really good. The enablement process is so easy I was looking around to see what I did wrong, but it just works.
  • After the application caches all the content, the page responses are fast. This is also combined with CloudFlare’s caching services, so I’m hoping my site will be performant across the globe, despite it running from a shared App Service Plan in the US East.

It hasn’t been an entirely bump-free journey though, for instance:

  • Defining the RSS feed took some tweaking. In the end I just loaded what I’ve got into FeedBurner and present the FeedBurner URL on the homepage for users.
  • Some of the slugs from my previous Ghost blog aren’t quite the same as what I’ve set here, so some of my Disqus comments are missing.
  • It took me messing around for a couple of days to get it running. Definitely not the best use of limited time, but that’s how self-education works I guess.

This site is still static in some sense. It’s not backed by any database; all the content is just a bunch of markdown files on the file system. To build it I:

1) Created a new MVC with Razor project, and stripped out anything I didn’t need.
2) Left the default controller, “Home”, in place, and created a new one for posts. The Home controller just serves up the homepage and the RSS feed:


3) Altered the Home Index view to contain the homepage contents, and also list each of the posts in chronological order:


4) Created a Post View, which renders the content of each post:

Post View

5) Defined a Post Model, to hold the post content and the metadata associated with it:

Post Model

6) Created a Singleton ContentManager class, which loads the posts into memory and also constructs the RSS feed:

ContentManager Class

7) Created the Markdown files for the posts. I also have a metadata entry of “Draft”, so I can draft up posts but they’ll be ignored by the content manager if published prematurely:


8) And finally defined routes to capture any UrlSlug and render the post related to it. This way the slugs are only defined in the post files themselves, rather than as explicit routes:


I’m still making some final tweaks, but once I’ve done those and refactored it I’ll publish the project to Github or Bitbucket so that you may use it if you’re wanting to make your own blog engine.

I should mention too: Wyam is amazing. The effortlessness of building static sites with it is unparalled, and I don’t want this post to be misconstrued as me ditching it because it’s bad. It’s a fantastic product, I’m just a sucker for self-inflicting punishment.