On Programming

A discussion of programming strategies and results

Octopress and Org-Mode

| Comments

OUT OF DATE

WARNING This post is out of date. A newer infinitely better method is located at http://blog.paphus.com/blog/2012/08/01/introducing-octopress-blogging-for-org-mode/.

I am making the switch to octopress for my blogging platform. Those of you that know me know that I am an avid user of Emacs Org-Mode so naturally I want to use it to write my blog.

The first tutorial I followed is located at http://jaderholm.com/blog/blogging-with-org-mode-and-octopress. It managed to get me up and running but I noticed a few issues with it. The first issue was that it didn’t handle exported babel blocks like dot/graphviz. To fix that I needed to change two items in my .emacs file. First I define a save-then-publish function which I found online. Sadly I lost the original location.

1
2
3
4
5
  (defun save-then-publish ()
    (interactive)
    (save-buffer)
    (org-save-all-org-buffers)
    (org-publish-current-project))
Then I declared an additional project that handles the publishing of image files to the proper directory to be synced with rsync.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  (setq org-publish-project-alist
        '(("blog-org" .  (:base-directory "~/blog/source/org_posts/"
                                          :base-extension "org"
                                          :publishing-directory "~/blog/source/_posts/"
                                          :sub-superscript ""
                                          :recursive t
                                          :publishing-function (set-octopress org-publish-org-to-html unset-octopress)
                                          :headline-levels 4
                                          :html-extension "markdown"
                                          :body-only t))
          ("blog-extra" . (:base-directory "~/blog/source/org_posts/"
                                           :publishing-directory "~/blog/source/"
                                           :base-extension "css\\|pdf\\|png\\|jpg\\|gif\\|svg"
                                           :publishing-function org-publish-attachment
                                           :recursive t
                                           :author nil
                                           ))
          ("blog" . (:components ("blog-org" "blog-extra")))
          ))
This worked great, but then I noticed that code blocks were getting exported as simple <pre> blocks and not getting highlighted. I managed to fix that with a simple regular expression to replace the code blocks before export and then restore the file back to its original state after the export. Please note that this is the first iteration of the function so it is not robust, it will only work for blocks that are simple begin_src blocks with a language specified. If you would like to improve on the function the comment section is open and I would appreciate it!

NOTE I had to locate this on pastebin because my function was matching its own code and messing with the highlighting. Now instead of hitting C-c C-e F I just hit M-x save-then-publish ret and everything seems to work. Hope this helps someone out there looking to use org-mode to its full potential!

Comments