Web publishing with iPad, Dropbox and Mercurial

I was playing around with the iPad the other night and noticed that there is an app for editing plaintext files directly in Dropbox. And there it started.

Dropbox is a cool service which syncs your files between different devices. It supports desktop PCs running OSX, Windows, and Linux, Android and iPad. I’ve used it a long time already to sync certain files between laptop and fileserver at home. And lately also Android phone. Very easy to use stuff.

Mercurial is a version control system designed for mainly source code. But I’ve used it to store pretty much anything I produce. And all of my repositories are automatically backed up to multiple machines with Mercurial and some cron jobs. Mercurial is cool that way, it makes distributing files and history really easy.

I use a Sphinx publishing system on top of Mercurial. All content is stored there and then rendered to HTML, committed to another repo and pushed to the web server.

With the iPad Dropbox-integrated text editor I got an idea.

What if I put the mercurial work area to Dropbox and edit the files with iPad while laying on the sofa? And it is automatically updating my CMS and web pages. Could it work?

Of course it would! All components are there, it just needs some glue in between the pieces.

One way of doing this is in the server side where the central Mercurial repository is. That way it is easier to do two-way automatic syncing to the iPad.

Mercurial has really easy to use hook system. With the hooks it is easy to do stuff whenever something happens in the repository. Here we are interested when some new content is pushed to the repository. In that hook we automatically update the workarea to the latest revision which was just pushed to the repo. Now we have always the latest stuff available for the iPad.

To get the changes from iPad back to the repo we need some notification that the content has changed. It’s a little trickier, and we have multiple options. One we would be to use inotify. So, whenever the files are changed automatic commit is done to the repository. Now we have changes going both ways between Mercurial and Dropbox.

And to get the content to the web we need another hook in the repository. Always when the content changes it is automatically rendered and published by the CMS. This last step is quite specific to my CMS, but everything else here is really generic.

Of course this has problems when there are conflicts in the Dropbox workarea. Somebody has to resolve them with a merge tool by hand. And the iPad is not suitable for that. But when I’m the only one editing the files there are no problems.