Jack Baty

Director of Unspecified Services

Creating Kirby posts in Emacs

Sometimes I'm just chugging along with something in Emacs and I want to start a new Kirby post. Instead of always finding my way to the Kirby panel, I modified the small lisp function I wrote for creating Hugo posts. It looks like this:

(defun jab/kirby-new-post (title &optional)
  "Create and visit a new blog post for the prompted TITLE."
  (interactive "sTitle: ")

  (let* ((slug (s-dashed-words title))
         (default-directory (concat "~/sites/blog-kirby/content/1_posts/"
                            (format-time-string "%Y/%m/")
                            (format-time-string "%Y%m%d_")
                            slug "/"))
         (fpath (concat default-directory "/post.txt")))

         (make-directory default-directory)

    (write-region (concat
                   "Title: " title
                   "\n\n----\n\nSummary: "
                   "\n\n----\n\nDate: " (format-time-string "%Y-%m-%d %H:%M:%S")
                   "\n\n----\n\nText: "
                   "\n\n----\n\nTags: ")
                  nil (expand-file-name fpath) nil nil nil t)
    (find-file (expand-file-name fpath))))

This prompts me for a title, sluggifies it, then creates a new file in ./1_posts/YYYY/MM/YYYYMMDD_slug/post.txt

I'm sure there's a cleaner way to do this. I should probably not hard-code the blog's path, but this works and I can get right to writing. Note that it skips putting the new post in the drafts folder. Since I write locally and rsync to the server, I don't use the draft status.