为新建博客文章增加Org Capture模板
dotemacs-org-post-file
函数会在博客文件夹对应的年份目录下新建文章;
(defun dotemacs-org-post-file () (let* ((filename (read-from-minibuffer "New post filename: ")) (post-dir (concat dotemacs-org-site-dir "/org/posts/" (format-time-string "%Y")))) (unless (file-exists-p post-dir) (make-directory post-dir t)) (find-file (expand-file-name filename post-dir)) (tempel-insert 'blog-title))) (setq org-capture-templates `(("p" "Post" plain (function dotemacs-org-post-file) "" :jump-to-captured t :immediate-finish t)))
此外,这里会调用 tempel 自动增加文章头部,org-mode中 blog-title
的定义如下:
(blog-title "#+TITLE: " n "#+DATE: " (format-time-string "<%Y-%m-%d %a %H:%M>") n "#+STARTUP: hideblocks" n "#+OPTIONS: toc:nil" n)
然后,就可以愉快的写作啦!