Coder's Cat

Blogging with Emacs and Wordpress


Emacs for blogging: write post in org-mode, everything goes well

Hexo and Jekyll are good, but…

I write about programming, technology, and other topics.

10 years ago, I started blogging with WordPress and then transferred to Jekyll several years later, then continually moved to Hexo.

Jekyll and Hexo are fascinating tools for programmers to generate content files into the HTML page. We only need to publish generated results onto a server.

The generated pages are minimized and super fast. We can use Git or any other version control tools to manage posts.

In one word, with these tools we can blog like coding, it’s the style of programmers.

Blogging with Emacs and Wordpress

I begin this new blog recently, for practicing another style of writing: writing for others.

However, I realized recently, WordPress is still a good choice for technical blogging.

Wordpress is the most popular tools for building a site, it’s more than 20 years old and with many existing good plugins.

Org2Blog is amazing

I have used org-mode for about 2 years. I won’t change to write on the dashboard of Wordpress. Org2Blog is the reason I want to use Emacs for blogging. The experience of writing in org-mode is amazing.

The whole workflow is:

  • Use org-capture to create a new file of org-mode
  • Edit the post
  • Use the command org2blog/wp-post-buffer-and-publish to commit the post to Wordpress.

Some handy configurations

This is my org=capture-templates. All posts are stored in the directory: ~/Dropbox/org/blog/, images are stored in a subdirectory of name imgs.

(defun create-org-file-with-dir (dir)
(lexical-let ((dir dir))
(lambda ()
(let ((name (concat (format-time-string "%Y_%m_%d_")
(read-string "file-name: "))))
(expand-file-name (format "" name) dir)))))

(defun create-blog-file ()
(funcall (create-org-file-with-dir "~/Dropbox/org/blog/")))

(setq org-capture-templates
'(("t" "Todo" entry (file+datetree "~/Dropbox/org/")
"** TODO %?\n %i\n " :empty-lines 1)
("b" "Blog file" entry (file create-blog-file)
"** New Post\n#+BLOG:\n#+CATEGORY:\n#+TAGS:\n#+DESCRIPTION:\n#+ATTR_WP: :syntaxhl light=true\n#+TITLE: %^{desc}\n " :empty-lines 1)

It’s easy to insert code snippet use org-insert-structure-template. Except for code, we can also insert various kinds of templates:

I wrote this elisp code org-insert-image to insert image from clipboard:

(defun org-insert-image ()
(let* ((path (concat default-directory "img/"))
(image-file (concat
(format-time-string "_%Y%m%d_%H%M%S.png"))))
(if (not (file-exists-p path))
(mkdir path))
(shell-command (concat "pngpaste " image-file))
(org-insert-link nil (concat "file:" image-file) ""))

Join my Email List for more insights, It's Free!😋

Tags: Writing