I know that Jekyll is supposed to be a coder friendly blogging platform, but sometimes opening yet another buffer in your text editor can be a pain, e.g. when you've got a couple hundred buffers open, you're deep in a project, and you just want to make a short post. I figure if I want to blog more I should oil and smooth out the process. So I wrote a few short functions for setting up a new blog post (I'm sure others have done this too) and helping me publish changes quickly.
Here's what I use to create a new post, you'll probably want to look it over and update it to work for yourself.
(defun wrap-in-quotes (s) (format "\"%s\"" s))
(defun create-new-blog-post (title categories slug)
"Creates a new jekyll blog post. Assumes a lot about the environment."
(interactive "sPost title: \nsPost categories (uppercased, comma seperated): \nsPost slug (optional, can be guessed from the title): ")
(let* ((year (format-time-string "%Y"))
(date (format-time-string "%Y-%m-%d"))
(cleaned-title (replace-regexp-in-string "[\'_]" "" title))
(cleaned-title (replace-regexp-in-string "&" "and" cleaned-title))
(downcased-title (downcase cleaned-title))
(slugged-title (if (not (string= slug ""))
slug
(replace-regexp-in-string " " "-"
downcased-title)))
(filename (concat "~/sync/code/blog/_posts/" year "/" date "-" slugged-title ".md"))
(formatted-categories (mapconcat 'identity
(mapcar 'wrap-in-quotes
(split-string categories ", "))
", "))
(default-content (format "---\ntitle: %s\ncategories: [%s]\nlayout: default\npublished: true\n---\n\nHappy blogging!\n"
title
formatted-categories)))
(find-file filename)
(insert default-content)))
I bind it to a keychain just for blogging.
(global-set-key (kbd "s-b n") 'create-new-blog-post)
Next I run a few commands to deploy using ansible.
(defun publish-blog (message)
"Commits posts in the blog and runs ansible to publish it. Assumes a ton about the environment."
(interactive "sCommit message: ")
(let ((default-directory "~/sync/code/blog/"))
(shell-command "git add .") ;; Careful, you better know what you're committing!!
(shell-command (format "git commit -m \"%s\""
message))
(shell-command "git push origin master"))
(eshell)
(goto-char (point-max))
(eshell-kill-input)
(insert "cd ~/sync/code/isospectral/ansible_playbooks/")
(eshell-send-input)
(insert "ansible-playbook -i hosts blog.yml -K")
(eshell-send-input))
Also mapped to a similar hotkey.
(global-set-key (kbd "s-b p") 'publish-blog)
You'll probably want an up-to-date version, which as of the time of this post can be found at my fork of the prelude starter kit.