Press "Enter" to skip to content

First Post with Spacemacs and org2blog

Haven’t been blogging for quite a while. I recently got around to redeploying and updating my WordPress blog to AWS Lightsail. It works so much better (and less expensive) now!

The Dev team here at Omnyway wanted to start blogging on our company WordPress blog about all the cool Clojure stuff we’re open sourcing. But they all like to use Emacs Org Mode for their writing.

I had to figure out how to go from Emacs org mode to WordPress, so I am first trying it here on my personal blog. Since I use Spacemacs (in holy mode of course) as my form of Emacs, I wanted to add it as a Layer.

Spacemacs prefers you to have layers that combine packages and configuration. I could have just added it to dotspacemacs-additional-packages in the spacemacs init file but I wanted to try doing it as a layer. I’ve tried (unsuccessfully) to create my own layers before, but I was determined to get it to work this time! Turns out there isn’t really that much of an advantage of using a layer in this case other than being able to pull it from github dynamically.

Creating a Layer

Use Spacemacs to make a private layer template

You don’t need to do this but it helps to have a scaffold template. While inside Spacemacs:

<META-x> configuration-layer/create-layer

This will prompt you for a directory where your private layers go (mine was ~/.spacemacs.d/layers). Then it will prompt you for the name of the layer. In this case org2blog.

It will then create a README.org and a packages.el with some things filled in. The README will be used for the help for the package.

Update the scaffold files to do the actual work

I updated the packages.el to the following (removed most of the boilerplate below)

;;; packages.el --- org2blog layer packages file for Spacemacs.

(setq org2blog-packages
  '((org2blog :location (recipe :fetcher github
                                :repo "org2blog/org2blog"))))

(defun org2blog/init-org2blog ()

  (use-package org2blog)
  ;(require 'org2blog-autoloads)
  )
;;; packages.el ends here

The first statement setq org2blog-packages will pull the package from github and the second statement org2blog/init-org2blog will be used to initialize the package when its lazily loaded.

Then needed to add the layer (org2blog) and its basic config to the spacemacs init file (~/.spacemacs in my case).

The config specifies a list of blogs you can log into. This example shows only one. A more complicated config could go into the dotspacemacs/user-config section of the spacemacs init file instead if you prefer.

dotspacemacs-configuration-layers
 '(
   (org2blog :variables
     org2blog/wp-blog-alist '(("my.blog.com"
                               :url "https://my.blog.com/xmlrpc.php"
                               :username "joe")))
    ;; ... additional layers                               
  )

Once you have that all set, restart Spacemacs.

Taking it for a spin

After you restart Spacemacs (and hopefully get no errors). Issue the command:

META-x org2blog/wp-login

It will let you select which blog (in this case my.blog.com) and will ask you for the password.

Then command:

META-x org2blog/wp-new-entry

At that point you can start writing your post! It will have put a few headers in that you could fill in at the top.

When you are ready to push it to your WordPress blog just incantate one of the following:

Publishing Keybindings

post buffer as draft C-c M-p d M-x org2blog/wp-post-buffer
publish buffer C-c M-p p C-u M-x org2blog/wp-post-buffer
post buffer as page draft C-c M-p D M-x org2blog/wp-post-buffer-as-page
publish buffer as page C-c M-p P C-u M-x org2blog/wp-post-buffer-as-page