Saturday, January 30, 2010

Posting to Blogger from Git

GitBlogger is a small tool, written in Python, that allows you to write blog posts in reStructuredText using an editor of your choice, commit your posts to a git repository, and then have them automatically converted to Blogger blog posts when you push your repository to a "remote" repository ("remote" in quotes because "remote" may simply mean "another copy of the repository on your local system").

I put this together to scratch a few of my own itches, which may not be the same as yours:

  • I don't want to write blog posts in HTML. Our life on this planet is short and we shouldn't waste it with all those angle brackets.
  • I want to use a real editor, rather than editing text in browser text fields.
  • I want to use some form of version control on all of documents, not just my source code. Git has proven itself to be extremely flexible and easy to work with.
  • I want things to be handled as automatically as possible.

GitBlogger handles the task of synchronizing changes in your git repository to your Blogger blog. It specifically does not make any attempt to take changes you've made to your blog via other mechanisms and somehow propogate them back to the repository -- the model here is that your blog is primarily a display mechanism.

GitBlogger handles adds, updates, renames, and deletes.

How it works

  1. You compose your post using your editor of choice and commit your changes to your local repository.
  2. When you're ready, to use git push to transfer the changes to a remote repository that has been configured to use GitBlogger's post-receive hook services.
  3. GitBlogger maintains a local database that allows it to associate files in your repository with specific post id's on your Blogger blog.
  4. GitBlogger then uses git diff-tree to generate a list of files that have been created/renamed/updated/deleted as part of the commits since you last pushed the repository.
  5. For each file, GitBlogger will either create a new post in your Blogger blog, delete a Blogger post, or update the contents of an existing Blogger post.
  6. GitBlogger handles the conversion from reStructuredText to HTML, and extracts certain metadata (e.g., tags or draft status) from the documents docinfo section.

Caveats

I'm using GitBlogger "in production" on two sites right now, and the only mishaps I've had have been in the positive direction (duplicate posts) rather than the negative direction (which would be erroneously deleted posts). That said, it has not seen extensive testing nor use outside of my own environment.

Documentation is pretty light at the moment. The included README file shows a sample configuration, but the docs could use some fleshing out.

I'd be happy to hear about your success stories, suggestions for improvements, or problems that you have run into using this software.

0 comments:

Post a Comment