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:

git submodule add https://github.com/punchagan/org2blog.git elisp/external/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:

machine virtuouscode login MYLOGIN password MYPASSWORD

With that set up I can configure org2blog:

; It seems I need to do this first to make package loading work

(require 'netrc)
(require 'org2blog)
(setq abg-netrc-vc 
      (netrc-machine (netrc-parse "~/.netrc") "virtuouscode" t))
(setq org2blog/wp-blog-alist
         :url "http://avdi.org/devblog/xmlrpc.php"
         :username (netrc-get abg-netrc-vc "login")
         :password (netrc-get abg-netrc-vc "password")
         :tags-as-categories nil)))

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:

(global-set-key (kbd "") 'org2blog/wp-new-entry)
(global-set-key (kbd "S-") 'org2blog/wp-post-buffer)

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 and tags will be generated instead of and .


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: