My New Site
It has been a while since I posted something and the primary reason is that I’ve been moving my content from BearBlog to it’s own space (The site you are reading this on currently). There are a couple of reason for it so let me explain the “Why”, the “What”, and the “How”.
Why
The challenge sounded kind of cool. Nothing too difficult but a couple of smaller intricacies that would require a bit of thinking.
Don’t get me wrong, I really like what Herman is doing with BearBlog and I love the idea of the tiny internet but this way I have a fully customised platform that I control from the ground up. Using this platform I can also branch out from simple blog posts and branch out into things like a design pattern library, more engagement with my readers, and who knows what else?
What
It’s a simple MVC app built on .Net 8 using Razer pages. I’ve forgotten how easy Razer pages make things.
The blog posts themselves are a bit more tricky. I write all of my notes in markdown using Obsidian. Usually when I think something is publish worthy, I’d copy it to BearBlog (all of it runs on markdown already). I wanted to keep a similar workflow going so instead of storing my blog posts in a database, I’m simply keeping them in .md files and publishing those, using GitHub actions. The website is designed to pick up changes in the files and reload the blog storage singleton. There are some intricacies, some I have already figured out and some that have not seen much attention yet, but that brings us to the How.
How
Markdown is a very simple syntax, as such converting it to HTML should be easy peasy, right? Yes, but not. Yes, if you are clever enough, you can simply use a cool library like Markdig to parse the markdown for you. No, if like me, you prefer to write it yourself to maintain full control of things (also I did not spot this library until I was well into the process).
Parsing markdown, at it’s core, is a couple of regex strings to match things like links, images, typography, and inline code. But it gets a bit more intricate when you need to parse a code block and then, even more so, when parsing a list. A list in particular is annoying because I wanted to keep the ability to do nested lists and also to be able to change from ordered to unordered lists on the fly. I also wanted to be able to have lists that start at numbers other than 1 and also skip a few if the theme requires it. Ultimately it was a lot of fun working it all out and very rewarding in the end.
I might to a blog post at some point to explain it in more detail, or I’ll simply put the platform itself in a public repo for all to behold.
One library I do want to give a shout-out to is Highlight.js which I use to highlight syntax in my code blocks.
private static string ParseStrongText(string markDownLine)
{
const string strongRegex = @"(\*\*|__)(?!\1)(.+?)(?<!\1)\1";
return Regex.Replace(markDownLine, strongRegex,
x => $" <strong>{x.Groups[2]}</strong> ");
}
It makes it really easy and I think it’s a nice touch, and a necessity for a site that by-and-large focused on coding stuff.
What’s next?
Now that all of this is up and running, I can slowly refine it (the parser still needs to be able to parse tables, for instance), fix up the styling to be more in-line with my terminal-esque theme on BearBlog. Reader interaction is something else I’m quite keen on allowing things like easy-sharing or commenting on posts, but that will all come with time.