Posting to Jekyll with Emacs

So I’ve got this website running, and I’d like to try to actually start writing posts now and again. I’m using Jekyll to generate it since static site generators are All The Rage and Jekyll seems to be the most popular/best-maintained one (probably thanks to the good folks at Github).

Anyhow, I figure the easiest way to force myself to actually write stuff is to make the process of writing a new entry as easy as possible. I’m an Emacs devotee, so I wrote some elisp to create a new post in the format that Jekyll wants:

(require 'cl)
(setq website-dir "/Users/doug/code/fun/site/")

(defun sluggify (str)
   "[^a-z0-9-]" ""
   (mapconcat 'identity
              (remove-if-not 'identity
                             (subseq (split-string
                                      (downcase str) " ")
                                     0 6))

(defun new-post (title)
  (interactive "MTitle: ")
  (let ((slug (sluggify title))
        (date (current-time)))
    (find-file (concat website-dir "src/_posts/"
                       (format-time-string "%Y-%m-%d") "-" slug
    (insert "---\n")
    (insert "layout: post\n")
    (insert "title: \"") (insert title) (insert "\"\n")
    (insert "date: ") (insert (format-time-string "%Y-%m-%d %H:%M:%S")) (insert "\n")
    (insert "---\n\n")

It’s pretty straightforward. If, like me, you’re primarily familiar with languages designed after 1985 or so, Elisp’s function names are likely to be a bit counterinuitive; the Elisp Cookbook is really helpful for figuring out how do do things like filtering lists, etc.

I was considering using this space to wax poetic about the value of customizing one’s environment to automate and simplify common tasks, but I think Steve Yegge already did a pretty good job in his essay on living systems. So: learn Emacs Lisp or VimScript, bash or zsh, Python or Ruby, and make your environment do what you want!