After searching around for a good writing platform for Sourcing.io's blog, I decided to roll my own with Sinatra. While I like the idea of static site generators like Jekyll, I wanted the kind of flexibility you can only achieve with a custom solution. Indeed, it only ended up taking a few hours of my time to put together.
The end result is before you. I've decided to open source the application since it's so simple and generic. You can find it at the maccman/sinatra-blog GitHub repo.
If you're interested, have a browse throughout the source. I think the application is an especially good example for:
- Using Sinatra routes as middleware
- GZip and caching
- RSS feeds with Builder
- Sprockets, Stylus and asset management
- Markdown and Erb
- Unicorn and Heroku
All posts are written in Markdown, and are
.md files in the project's
posts directory. The filename ultimately becomes the post's slug. Before the Markdown is rendered, the post is evaluated as Erb, which gives you the chance to set a few variables such as
author. For example, here's
<% title 'Introducing Sourcing.io' date '17th December 2013' author 'Alex MacCaw' %> Hiring Engineers is a hard problem...
Take a look at the code in post.rb to see how this all works — it's all fairly straightforward.
I really like projects that come with a simple Heroku setup guide, and in the spirit of that let me provide you with one. First clone and download the Sinatra application.
git clone [email protected]:maccman/sinatra-blog.git cd sinatra-blog
Next let's create the Heroku app (and setup a Heroku account if you haven't already). Substitute
myblog for the name of the app you want to create.
heroku create myblog heroku labs:enable user-env-compile heroku addons:add memcachier:dev
We're enabling the
user-env-compile lab flag since we want compiled assets to be cached for faster deploys. Lastly, let's deploy our application:
git push heroku master heroku open
I look at sinatra-blog as simply a good blogging scaffold to get started, and as such it's intended to be forked and modified. Feel free to open pull requests for any generic and simple behavior you think is lacking though.