New Tech Blog with Middleman

The old tech blog was running in PHP. Wordpress maybe? Who knows or cares. Anyway, the ops guys said something like "Hey, none of you lazy developers have written a blog post in over a year, and we've got this unpatched PHP instance running, we're going to take the damn thing down." Actually they were much nicer than that. But that's what they should have said.

None of us lazy developers objected. How could we? It was true. But silently we thought, "Having a tech blog is a good thing!" On the other hand, we didn't want to ask ops to patch PHP only to have them send the same email again in a year. Plus we wanted to do something cooler than PHP and Wordpress, I mean really.

Middleman

What we really needed was a simple static blog. Then ops could just serve it up with Apache or whatever. It would be simple and fast, and it wouldn't require PHP with its patches, etc. But who wants to maintain a static site? So we decided to use Middleman which gives us some of the handy rails-like tools we are used to, and then generates a static site for you. Awesome! Now creating a new blog article is easy.

# if you don't already have it
# of course, this is a private repo so it won't work if you aren't a PLM-er
git clone git@github.com:patientslikeme/tech-blog.git
cd tech-blog
bundle
# or if you do have it just pull any changes
git pull
# then generate your article and start the server.
bundle exec middleman article mice-eating-elephants
bundle exec middleman server

Then open your new article in your text editor (it's just markdown) and start editing. Visit http://localhost:4567 to see it in your browser.

Our styles are from another project, included in our blog using git subtree. Actually, our fonts are in /common/app/asssets/webfonts, which isn't what Middleman seems to expect, but a symolic link seems to have dealt with that (after a couple of hours messing with the internals of sprockets and middleman-sprockets, d'oh).

We added a file source/stylesheets/syntax.css.erb

<%=Rouge::Themes::Github.render(:scope=>'.highlight')%>

And we included all our stylesheets in layout.erb:

<%=stylesheet_link_tag'common/global','application','syntax'%>

Since some of the articles were really old, and we didn't want to show them in "recent posts," we made this change as well:

<%blog.articles[0...5].eachdo|article|%><%unlessarticle.date<1.year.ago%><%# added this %><li><%=link_toarticle.title,article%><span><%=article.date.strftime('%b %e')%></span></li><%end%><%# and this %><%end%>

Actually, to get 1.year.ago to work we had to add require 'active_support/all' to config.rb.