Writing an org-capture template and defun for blog posts

So I’d asked a couple of friends and one of them was kind enough to help me write this function. i mean, they wrote it and i just changed it up to make it work according to my needs:

(with-eval-after-load 'org-capture
  (defun taingram/org-new-blog-post ()
    "Gets user input for blog post title and uses it to construct the
filename to create. Also uses the title in the capture form so I don't have to type it out again."
    (interactive)
    (let* ((title (read-string "Post Title: "))
           (filename
            (read-string "Filename: "
                         (concat (org-hugo-slug title) ".org"))))
      (set-buffer (find-file-noselect
                   (file-name-concat "~/git/personal/blog/org/drafts/" filename)))
      (insert "#+title: " title)
      (newline))))

(setq org-capture-templates
      '(("b" "New blog post"
         plain
         (function taingram/org-new-blog-post)
         "#+date: %u
#+description: %^{Description} \n
%?"))

the title doesn’t show up till after the file is opened but it works. for a version of this that shows the title too paste.sr.ht

1 Like