Blogging With Emacs

Xah Lee asked me to write about my blog publishing process and how an article gets from Emacs to my site. I've written about most of the parts of the process in various posts but it might be useful to tie everything together in a single post for the benefit of any Emacs users who want to start a blog.

I write my posts with Org-mode in Emacs. As the Org Manual puts it,

“Org-mode contains an HTML (XHTML 1.0 strict) exporter with extensive
HTML formatting, in ways similar to John Gruber's markdown language,
but with additional support for tables.”

The Org-mode markup language makes it easy to insert formatting—such as bold, italics, and code—and hyperlinks to other documents. Even someone with no knowledge of HTML could produce very nice Web pages.

During the writing of the post, and afterward as a final check, I can send it to my browser to see what it will look like. That won't be exactly what you see on Irreal, of course, because I'm really just exporting the post to HTML and displaying in my browser without the benefit of the WordPress style sheet.

As I explain below, it's possible to write a post, export it to HTML, and then paste it directly into your site's editing window but I have a (much) better way. Once I'm satisfied with the post I export it directly to my site using org2blog. Making one call to org2blog takes care of everything in a single step:

  • The post is converted to HTML
  • The HTML is uploaded to the WordPress process on my site
  • Any pictures or other images in the post are uploaded to the site and their links are adjusted to point to the site's machine rather than my workstation
  • The date and Post ID are added to the Emacs buffer containing the post
  • Information about the post is recorded in so that any updates to the post will result in the original post being updated rather than a new post being added.

By doing all these things, org2blog takes care of the majority of the bookkeeping chores associated with making a post.

When org2blog finishes with the upload, I save the file again (to save the date and Post ID that org2blog added), and call Magit to put it in Git. Then I call dired for my blog directory, type 【* .html to mark any HTML files and then 【D】 to delete the HTML files and any associated buffers. At this point, I'm done. The post has been published, the source for it filed away in Git, and extraneous files and buffers have been deleted.

My old blog, also called Irreal, was hosted on Blogger. Although there is a version of org2blog (by a different author) for Blogger I didn't use it. Instead, I used this function

(defun blog-post ()
  "Export an org buffer as HTML but only export the body."
  (org-export-as-html 3 nil nil "*blog-post*" t))

to convert the post to HTML and export the body. Then I would copy the *blog-post* buffer to the clipboard and paste it into Blogger's HTML editor. That worked fairly painlessly unless there was an image involved. Blogger stores the images in Picasa instead of with the post so doing things by hand can be a bit involved. I wrote about that here. I don't know if the Blogger version of org2blog handles pictures automatically but if it did, that would be reason enough to use it. If it is anywhere close to as convenient as the WordPress version it would be worth using. If you use org2blog on Blogger, leave a comment telling us about your experiences with it.

This entry was posted in Blogging and tagged , . Bookmark the permalink.
  • Suresh

    Cool stuff

  • scott

    I blogged recently about how to blog with org-mode and octopress.

  • Thanks for writing this.

    Just wanted to note that the file is meant to be a dashboard of sorts, to keep track of all the posts that were made from org2blog. This is an optional feature and is not necessary to have the updates working. The updates will work correctly, even without this, since the POSTID is saved along with every blog-post.

    • jcs

      OK, thanks. I didn't know that. Let me tell you directly how much I love org2blog. It makes publishing blog posts pretty much seamless.

      • punchagan

        Good to hear that! Thanks!

  • just want to say thanks. I just read in detail of the org file you sent too.

    for me, i code in raw html. The advantage of org or other format is that the text is plain and easy to read, write, edit. But that's also the disadvantage too i think, because it's less flexible. If you want your own tags, some custom javascript, css, etc, it'd be a problem, or one have to modify the lisp code that does the transform (or learn a new system of extensions). The extensibility, ease of extension, flexibility, learning curve, of CMS varies... But i think overall managed system is really the way to go precisely because they are controlled by automated programs that can be arbitrarily complex or smart.