Emacs Reboot #9: Blogging

I really like all the features that WordPress gives me. But I hate writing blog posts inside of WordPress. I want to do all my writing inside Emacs! Ideally, I’d be able to write my posts in Org-Mode, and publish them to my site from within Emacs. That’s today’s project.

First, I’m going to install org2blog. But org2blog needs xml-rpc.el as a prerequisite. I add the Tromey package archive (http://tromey.com/elpa/) to my package-archives, and install xml-rpc.el from there.

I then add the Git submodule for org2blog:

Remember, in episode 8 I set things up so that any directories in elisp/external would automatically be added to my load-path.

Now I need to give org2blog my login information. I decide to take the advice of the org2blog README, and keep my sensitive login information in my ~/.netrc file. The relevant .netrc line looks like this:

With that set up I can configure org2blog:

Now that I know about the netrc package, I think I might go back and get rid of that secrets.el file I created in a previous iteration, and move my Gist login info into .netrc.

Since I blog so much, I go ahead and make some global keybindings:

Now when I hit F9, I get a buffer that looks like this:


I can edit the buffer as an ordinary Org-Mode file, and then hit C-c d to publish it as a draft.

Now, there are a few nits left to iron out. For one thing, the default HTML that Org-Mode generates isn’t quite compatible with my blog’s stylesheet. I customize org-emphasis-alist to ensure that <em> and <strong> tags will be generated instead of <i> and <b>.


Now I turn my attention to making sure source code listings look pretty. First, I install the htmlize package using the package manager, so that Org-Mode can generate pretty source-code markup. Then, I change the org-export-htmlize-output-type option to css to cause it to generate HTML marked up with classes instead of inline styles.

The marked-up output won’t do me much good without a stylesheet to map classes to styles. Rather than write one from scratch, I tell Org-Mode to generate one for me with M-x org-export-htmlize-generate-css. Here’s a small sample of the generated code:

I pull out the CSS, save it as http://avdi.org/stylesheets/code.css, and update my blog template to link to that stylesheet.

And that’s it! Now I can blog from the comfort of Org-Mode.

And yes, as you might have guessed: this post was written and posted from inside of Emacs. Even the screenshots were automatically uploaded and linked into the post by org2blog!