Alex Henning home about projects blog

My Blogging Work-flow

I've been blogging for less than a week. So far, I have the workings of a simple work-flow for blogging. Below, I've documented the basics.


The directories of the blog.

1:  (setq
2:   blog-directory "~/Dropbox/blog/"
3:   blog-posts-directory (concat blog-directory "_posts/")
4:   blog-base-directory (concat blog-directory "org/posts/")
5:   blog-draft-directory (concat blog-directory "draft/"))


This allows me publish my entire blog with C-c C-e X blog. It exports any changed files from the blog-base-directory into blog-posts-directory. It should be unnecessary to change any of the below, as long as you modify your settings properly.

 1:  (setq org-publish-project-alist
 2:        `(
 3:          ("blog"
 4:           ;; Path to your org files.
 5:           :base-directory ,blog-base-directory
 6:           :base-extension "org"
 8:           ;; Path to your Jekyll project.
 9:           :publishing-directory ,blog-posts-directory
10:           :recursive t
11:           :publishing-function org-publish-org-to-html
12:           :headline-levels 4 
13:           :html-extension "html"
14:           :body-only t ;; Only export section between <body> </body>
15:      )))


C-c C-e X blog is nice, but it involves being in org mode and does strain the pinky a little. However, M-x blog-publish would be more convenient, and able to be run from any buffer.

1:  (defun blog-publish ()
2:    (interactive)
3:    (org-publish-project "blog"))


Next, I want to be able to draft a post easily without publishing it, just as a preliminary draft. The following function allows me to easily do this with M-x blog-draft some-filename.

1:  (defun blog-draft ()
2:    (interactive)
3:    (let* ((result (read-from-minibuffer "File: " nil ))
4:           (buffer (generate-new-buffer (concat blog-draft-directory result ".org"))))
5:      (set-buffer buffer)
6:      (set-visited-file-name (buffer-name buffer))
7:      (switch-to-buffer buffer)))


I would also like to be able to effortlessly post a draft when I am ready without having to remember jekyll's naming convention. M-x blog-post will do that.

 1:  (defun blog-post ()
 2:    (interactive)
 3:    (save-buffer)
 4:    (let* ((date (calendar-current-date))
 5:           (filebase (car (last (split-string
 6:                       (buffer-file-name (current-buffer)) "/"))))
 7:           (filename (format "%s-%s-%s-%s" (caddr date) (car date)
 8:                         (cadr date) filebase))
 9:           (filepath (concat blog-base-directory filename)))
10:      (message filepath)
11:      (shell-command (format "mv %s %s"
12:                             (buffer-file-name (current-buffer))
13:                             filepath))
14:      (set-visited-file-name (buffer-name (current-buffer)))
15:      (blog-publish)))


Using these commands, I can easily maintain my blog with emacs, draft posts and publish them. After I've played around with my work-flow a bit more, I'll try to make it into an easy download.

Any suggestions?

Posted on 24 October 2010 in org-mode emacs blogging elisp

<Previous: Online Thesaurus APIsNext: Yahoo Pipes, Easy Custom Alerts>

blog comments powered by Disqus