Blogging with org-mode

Wait, what?

My coworker makes infinite fun of me because I do everything in Emacs. He’s a proficient Vim user and uses it as a text editor like a master. Emacs, however, is almost a full operating system for me. Even though I haven’t figured out how to do video editing in Emacs (?), blogging is a task that’s possible to do with it.

I run a self-hosted WordPress instance on Scaleway. This is an affordable set up that gives me extreme flexibility.

The setup

As I described on my previous post, I use org2blog as the blogging package to post to WordPress. I have the following block on my .emacs file.

(require 'org2blog-autoloads)n(require 'netrc)nn(require 'auth-source)n(let (credentials)n	(add-to-list 'auth-sources "~/.authinfo")n	(setq credentials (auth-source-user-and-password "arenzana.org"))n	(setq org2blog/wp-blog-alistn	      `(("arenzanaorg"n		 :url "https://arenzana.org/xmlrpc.php"n		 :username ,(car credentials)n		 :password ,(cadr credentials)n		 :default-title "Hello World"n		 :default-categories ("emacs")n		 :tags-as-categories nil))))nn(setq org2blog/wp-use-sourcecode-shortcode nil)n;; removed light="true"n(setq org2blog/wp-sourcecode-default-params nil)n;; target language needs to be in heren(setq org2blog/wp-sourcecode-langsn      '("actionscript3" "bash" "coldfusion" "cpp" "csharp" "css" "delphi"n	"erlang" "fsharp" "diff" "groovy" "javascript" "java" "javafx" "matlab"n	"objc" "perl" "php" "text" "powershell" "python" "ruby" "scala" "sql"n	"vb" "xml" "go" "sh" "emacs-lisp" "lisp" "lua"))nn;; this will use emacs syntax higlighting in your #+BEGIN_SRCn;; <language> <your-code> #+END_SRC code blocks.n(setq org-src-fontify-natively t)

Naturally, I don’t post my credentials as part of my .emacs since I keep it under version control. Instead, I store it under ${HOME}/.authinfo.gpg like this:

machine arenzana.orgn  login adminn  password "mypassword"

The Lisp block creates a new blog instance called arenzanaorg (in case you want to have more than one blog). Include the XML RPC endpoint, credentials, and some defaults. In addition to this, I enable code highlighting. This is actually not working very well for me, because the CSS uses a very bright yellow color to represent strings for the emacs-lisp language (as you can see on previous posts). Instead, I’m just using the #+BEGIN_SRC #+END_SRC blocks (without specifying the language) to post code blocks. This gives grey blocks, but at least they’re readable. I’ve tried different options, without success. I’m not a front end developer, so to be honest, I’ve struggled working with all the CSS options for the HTML export option of org2blog.

The Workflow

The workflow is fairly simple for what I do. M-x org2blog/wp-new-entry. The first time you call this, it will prompt you to log in. Make sure you do so. Then it will open an Org buffer where you can edit the defaults and type away.

Once I’m done, I issue M-x org2blog/wp-post-buffer. This will upload the draft and give me the option to display the preview, where I can see what things will look like prior to publishing. After I’m happy with the final edits, I issue M-x org2blog/wp-post-bufffer-and-publish. This will post directly to WordPress.

Caveats

As I described above, syntax highlighting for emacs-lisp is not great and it doesn’t support Go (my language of choice).

Attaching images to a blog post is something I do after the fact, once the draft is up. I haven’t figured out a good way to upload and link images to a post straight from org2blog.