Categories
Posts

Remotely update Pelican via Dropbox

I wanted a way of forcing Pelican, the blogging platform I use, to update as soon as I had an article to publish. At the moment I have a cron job running every 20 minutes that updates Pelican with any new changes but I wanted a quick way of having Pelican update as soon as I wanted to in case I noticed an error in an article or wanted to publish a new one immediately.

Pelican does have a regenerate option but I find it is too unreliable, often causing it to fail without generating all files. It’s good for local development but when used in production, it’s too risky.

Instead, I wrote a shell script (based upon this answer over at Stack Overflow) that checks for the existence of a file in the Dropbox directory I store the articles in1. If the file exists, Pelican rebuilds the HTML and the site is updated. If the file doesn’t exist, the shell script simply exits gracefully.

https://gist.github.com/jordanmerrick/5362370.js

Amend the filename and location within the script then set it as a cron job to run every minute. Whenever you want to force update Pelican then simply create the required file (using touch, for example) in your content location on Dropbox. Within a minute, the server will be notified and Pelican will automatically update.

I have this saved as a cron job that runs every minute and moved my 20 minute interval to 2 hours in case I forgot to add the file to Dropbox.

  1. This requires having Dropbox installed on your server and Pelican configured to view a directory within as the location to grab content.