logo

Write-Only Memory:
The Blog of Kevin Thomasson

DIY, electronics, programming / whatever.

Hello, World!

I have had this idea about starting a blog for quite some time now. Each time I have made an mental effort to start, I could not get past the part were I would choose blogging software. There was always something that felt wrong for different reasons, and when thinking about making my own blogging software I always came to the (somewhat depressing) conclusion that it has been made too many times already.

Let's reimplement the wheel

This time around I am fed up with negative thoughts like "it's been done". Yes, it has been done, but not by me, and that's really all that matters. Making a custom blog engine is a really good opportunity to catch up on areas left neglected by work and spoil yourself with tailor made software supporting your own workflow. In my case, the technical areas I wanted to include were:

I have been a part of web projects that were built responsive, but I never had to really mess with the responsiveness myself. CSS3 is one of those things that I never really get sufficient need for but always think would be cool to use. The part about running .NET code on Mono and Linux is just a personal preference as I happen to have a Linux box running 24/7 at home.

My requirements

One aspect of being both developer and client at the same time is that you get to pick your own requirements, and it is sweet like sugar if you struggle with other peoples requirements all day. These are the basic requirements that I had from the start:

Lessons learned

Although the development went relatively smooth overall, there were some problems to solve along the way—most of which had its roots related to my decision to use the Mono framework. My development environment is .NET Framework running on top of Windows and my server environment is Mono on Linux. The platform difference in combination with my … *cough* … less than optimal concatenation of file paths was the source of the first problem. Windows and Linux uses different characters to separate directories and files in a path. I used the standard Windows backslash character between path components, which obviously is going to fail on Linux. The solution to these kind of problems lies in the usage of the class System.IO.Path:

		//Fail:
		string path = entryDirectory.FullName + @"\" + _contentFileName;
		
		//Will work:
		string path = entryDirectory.FullName + Path.DirectorySeparatorChar 
			+ _contentFileName;
		
		//Correct way:
		string path = Path.Combine(entryDirectory.FullName, _contentFileName);

The advantages of logging shouldn't come as a surprise to a developer, but I felt confident enough to ignore Murphy's law and logging altogether in my euphoria of having a good flow. It goes without saying that this strategy didn't bear fruit. Logging was essential to get the blog up and running on the server because there was very little information to gather about crashes in logs provided by the system or from error pages. I chose to use log4net as I have used it with good results in the past. Log4net was easy to get up and running quickly with Mono and it was log4net that revealed my sloppy path handling.

Result

I have to say I am a little surprised at how well Mono works. Mono feels mature and I am doubtless going to target it in future projects.

The responsiveness turned out to be less of a challenge to achieve than I anticipated. Using just a few media queries in the syle sheet and a small javascript for the menu the whole site was made responsive. Media queries in combination with use of the nth-of-type selector and some transitions gave me at least some more CSS3 under my belt.

All but one of my requirements is met as of today. The requirement that hasn't been met yet is about being able to have absolute control of the markup by turning off some automatic stuff. I'll implement that one when the need to do so arises.

Editing of blog posts as XML files on the servers file system works really good using two of my favourite applications; WinSCP for file transfers and Notepad++ with the plugin HTML Tag installed for editing. The XML files consists partly of meta data describing things like title, URL name and time stamp of the post, and partly by the markup itself (XHTML). Below is an example XML blog post file:

		<entry>
			<metadata>
				<title>Hello, World!</title>
				<urlTitle>hello-world</urlTitle>
				<description>Ends up in the html's meta description</description>
				<date>2014-05-28</date>
				<isCommentsEnabled>true</isCommentsEnabled>
				<isPublished previewPassword="admin123">true</isPublished>
			</metadata>
			<markup>
				<p class="preview">
					I have had this idea about starting a blog for quite some time ...
				</p>
				...
			</markup>
		</entry>

I think the blog software turned out pretty good in the end. Besides, I had a really good time implementing it. I have been working on hardware projects in my spare time for quite a while now, so this was a welcome change.

No software is ever finished, and there are a number of improvements and changes that can (and hopefully will) be made to this blog software. A search function would for example be nice to have, not to mention all candidates for refactoring in the code that needs some attention. However, for the time being, I am quite satisfied with the fact that you are using the result to read this!

Comments