Publishing with Jekyll, Dropbox and Crontab
My two blogs are powered with Jekyll, a static site generator. I love it and this is hands down the way to publish my content I prefer the most. I’ve been using it since I moved my blog out of Posterous and it has always served me well. I’m using it with a multi-site setup (which I will cover in a future post) and have published more than a hundred articles without any issues.
At first, I generated the site on my local machine and published it on my server using rsync. It was working well but quickly reach its limitations. As you may know, I’m traveling which means that I don’t always have access to a reliable Internet connection or have Internet at all. Secondly, I really wanted to be able to write posts which would be auto-published in the future.
As a result I’m now using Dropbox to sync my site to my server where it is automatically published using a cron job. This process is very easy to setup and made things much more easier.
The site is generated at a fixed time, two times a day. It is also constantly re-generated using a jekyll server in watch mode on a “draft” subdomain. This way I can always have a look at what the site will look like and check changes live. Only the draft domain includes future and draft posts.
First, you’ll need to add
future: false to your _config.yml file. It is
the only way to prevent
jekyll build from publishing future posts.
On the server, I installed the Dropbox daemon and used the Dropbox command line interface to exclude all folders except the one containing my site:
$ dropbox.py exclude add MyExcludedFolder
Here’s some parts of my Fabric’s fabfile which contains some useful tasks to run the site on your local machine and generate it on the server.
On your local machine use
$ fab serve to make the blog available on localhost:4000.
All future and draft posts will be visible.
As the blog is in Dropbox, it will be automatically synced to your server.
On the server, add a job in your crontab to publish it at fixed times:
30 10,23 * * * (cd /path/to/Dropbox/MyWebsite && /usr/local/bin/fab publish)
I use supervisor to have a jekyll process which serve the site on the draft domain. I use the following supervisor configuration:
Finally, I configure nginx to serve the two domains:
try_files $uri.html $uri/ =404; line. It permits building URLs to
html files without the html extension.
As a side note, varnish seats in front of all my domains and allows me to serve files quicker. It had no problem going through 30000 visitors in a few hours while one of my article was on Hacker News’ frontpage.
This setup allows me to write posts from anywhere (online using Writebox or from my mobile). It allowed me to continue writing posts while my laptop was at the repair shop, all this without having to download anything or install jekyll.
I’m now considering using Sparkleshare to achieve the same thing and at the same time having everything in a git repo. I’m sure this would be very easy to implement.
comments powered by Disqus