Vinod Kurup

Hospitalist/programmer in search of the meaning of life

Making Blog Posting Easier

Another piece of advice that I’ve heard over and over again is to make things easier. Automate! In that vein, I learned a little elisp in order to make it easier to create a new blog post. I create my posts in emacs, but I often cut and paste the YAML header from a previous post, which is tedious and time-consuming. Here is my new posting function:

(defun vk-blogpost (title)
  "Create a new blog post."
  (interactive "sPost Title: ")
  (let ((slug (replace-regexp-in-string " " "-" (downcase title))))
    (find-file (concat "~/web/"
                       (format-time-string "%Y-%m-%d")
                       "-" slug ".markdown"))
    (insert "---\n")
    (insert "date: " (format-time-string "%Y/%m/%d %H:%M:%S") "\n")
    (insert "layout: post\n")
    (insert "title: " title "\n")
    (insert "categories: \n")
    (insert "---\n\n")))

After asking me for a title, it creates a new file and massages the title to create a slug). It automatically enters the date of the post, both in the filename and in the YAML header. This took me about an hour to write, mostly in googling elisp commands. Hopefully, it will save time in the long run, but even if it doesn’t, it was fun to write :-)

Any feedback on my primitive elisp would be appreciated!