Mikael's blog

A developers sixth time trying to maintain a blog

Search And You Shall Find

Every blog should have a search box. Not because it's necessary, but because it's fun to implement.

A few weeks ago I ran across a small Javascript library called Lunr.js. It's basically a small text indexer that can rank search results and it's written entirely in Javascript, just the way I like it.

Setting up an index is really easy:

var searchIndex = lunr(function () {
  this.field('title', { boost: 10 })

Then you just add some documents to the index:

var doc = {
  id: "a-blog-post-title",
  title: "A Blog Post Title",
  content: "This is a crummy example blog post...",

Then you can search for it by simply calling searchIndex.search('crummy blog'); and that will return an array of objects with the properties ref and score.

ref is the id property of the indexed document and score is, well, how well it scored. The array will be sorted with the highest scoring result first in the array.

If you want you can supply a word list to the search index with words that should not be counted, but by default it has a list of common English words such as 'and' and 'if' so that they won't be ranked and affect performance.

Overall, I'm very happy with it. I created the SearchManager and connected it to the CacheManager so that it rebuilds the index if a new post is created or one is edited. I also configured the CacheManager so that it does not cache URLs starting with /search. That way I won't fill up my cache store with all different search results.

So, if browsing the archive isn't your cup of tea, then get searching folks!

by Mikael Lofjärd

New Drapes

I got tired of the old dark green design. It was too murky and spring is in the air, so I redesigned the site to be lighter and more "spring-y".

Old friends

var awesome = "Inconsolata is back!";

Inconsolata is back as the source code font and Open Sans makes up the majority of the text on the blog now with the exception of headers which are set in Racing Sans One.

All-in-all, I'm happier. And hopefully this can trigger my implementation of multiple pictures per post since I need that to report on my robot project progress. Summer is coming and summer means sun, and sun means solar power which in turn means that I need to speed things up if I want this project done before the (OMG spoiler alert!) new baby in the end of July.

by Mikael Lofjärd

4 Hours of Markdown

Wow, that was kind of exhausting.

I've completed my rewrite of all my blog posts into Markdown. Somewhere in the middle I found why my inline HTML didn't work and that made my old posts look almost acceptable, but the syntax highlighted source code didn't work anymore since I had moved the highlighting code into the marked configuration.

So on I went into the abyss, continuing to rewrite (more like edit) all my older posts. While I was at it I re-indented all source code examples into using 2-space indentation. Man, some posts do have a lot of source code in them. =)

I made good use of SSH for connecting to my server from my parents-in-laws' cabin (where I've spent the last week).

ssh -L 8080:localhost:5984 lofjard.se made sure I could connect to the CouchDB instance on lofjard.se.


  • All posts are now written in Markdown. You will not know the difference.
  • SSH is awesome.
by Mikael Lofjärd

Marked Up With Markdown

Desperate, as always, for lowering my blogging threshold I implemented Markdown syntax for the blog.

As I did this through use of the marked plugin I lost support for inline HTML (might be a setting though). For a few hours this means that my old blog posts will look ugly until I've gone through the backlog and converted it to Markdown.

by Mikael Lofjärd

Group Pressure

In a totally unoriginal move I'm now starting to wean myself off Facebook, starting by deleting the Facebook app from my phone and tablet.

Since almost everyone else in the tech sector seems to have done the same thing at least once, I don't feel that I have to post any particular reason for doing so other than being tired of it.

Since I'm not going cold turkey right away I will still check in on Facebook from my laptop, but the number of "feed reads" will hopefully be few and far between.

by Mikael Lofjärd