0

I'm trying to write an org-capture-template and supporting functions for it, for a blogging setup that uses individual org files within a specific directory for posts. i want this to work such that I get prompted for a title, which is used to generate the file name, the title metadata of the file, and a description, which is also used to generate another metadata variable. Based on this answer, I've come up with this:

(defun org-new-blog-post () (setq date (format-time-string (org-time-stamp-format :long :inactive) (org-current-time))) (setq title (read-string "Post Title: ")) (setq fname (org-hugo-slug title)) (setq description (read-string "Description: ")) (expand-file-name (format "%s.org" fname) "~/git/personal/blog/org/blog/")) (setq org-capture-templates '(("n" "new post" plain (function org-new-blog-post) "%(format \"#+title: %s\n#+date: %s\n#+description: %s\n\n\" title date description)"))) 

But this doesn't seem to work, and it just prints the output in the buffer I started with.

I understand that setting global variables in a defun is bad practice but somehow using a let form doesn't allow me to reference those variables in the capture template.

1

1 Answer 1

0

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.