Looking for static site generator? Look no more, use Rails!
Background
There are many too many of static site generators. Previously I had this blog generated in Jekyll. I've used Octopress as an out of the box solution which was far from being ready to use. It took me many hours to learn the api, how to style, how to deploy, how to write posts, where to put them, where to put images and how to reference them.
After 6 months of not using it and coming back to blogging I've realised I don't remember how to use octopress and jekyll. So instead of learning them again, I've decided to take another approach and write my own blog engine.
New idea
The problem that most blogs in static site generators has is that post parsing logic is mixed with view and website structure. So there are few rules I had to follow with my approach:
-
Focus on content and use Markdown
-
Post and all images (and other assets) should be grouped together in a single place.
-
Post should reference images locally as well, without complex paths. This means when writing post you don't need to remember how your blogging engine works.
before
/images/posts/cover.jpg
aftercover.jpg
-
Use as much of plain markdown as possible
before
{% img center /images/posts/cover.jpg %}
after![](2016-05-27-rails-as-a-static-site-generator-cover.jpg)
-
Separate blogging logic from the way it will be presented (web)
-
Keep it as a static site
Solution
The solution is to write blogging logic in ruby, add web interface through rails and convert to static website with wget command. Finally upload static website to S3 with s3_website tool.
I've tested many variations of wget commands and settled on this:
wget -r -l inf -k -nc -nH -p -E -e robots=off -P ./out http://localhost:3000
And here you go, you are reading static website generated from rails.