Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Org Capture interface to create new posts #33

Closed
kaushalmodi opened this Issue Jul 13, 2017 · 1 comment

Comments

1 participant
Owner

kaushalmodi commented Jul 13, 2017

Probably similar to #32

Owner

kaushalmodi commented Jul 21, 2017 edited

Commit 4e8ad4a adds the machinery needed for a fairly smooth new blog post writing using Org Capture.

Here is an example Org Capture setup:

(with-eval-after-load 'org-capture
  (defun org-hugo-new-subtree-post-capture-template ()
    "Returns `org-capture' template string for new Hugo post.
See `org-capture-templates' for more information."
    (let* (;; http://www.holgerschurig.de/en/emacs-blog-from-org-to-hugo/
           (date (format-time-string (org-time-stamp-format :long :inactive) (org-current-time)))
           (title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title
           (fname (org-hugo--slug title)))
      (mapconcat #'identity
                 `(
                   ,(concat "* TODO " title)
                   ":PROPERTIES:"
                   ,(concat ":EXPORT_FILE_NAME: " fname)
                   ,(concat ":EXPORT_DATE: " date) ;Enter current date and time
                   ":END:"
                   "%?\n")          ;Place the cursor here finally
                 "\n")))

  (add-to-list 'org-capture-templates
               '("h" "Hugo post for My Blog"
                 entry
                 ;; It is assumed that below file is present in
                 ;; `org-directory' and that it has a "Blog Ideas" heading.
                 (file+olp "blog-posts.org" "Blog Ideas")
                 (function org-hugo-new-subtree-post-capture-template)))

  ;; Do not cause auto Org->Hugo export to happen when saving captures
  (defvar modi/org-to-hugo-export-on-save-enable nil
    "State variable to record if user has added
`org-hugo-export-subtree-to-md-after-save' to
`after-save-hook'.")

  (defun modi/org-capture--remove-auto-org-to-hugo-export-maybe ()
    "Function for `org-capture-before-finalize-hook'.
Disable `org-hugo-export-subtree-to-md-after-save'."
    (setq org-hugo-allow-export-after-save nil))
  (add-hook 'org-capture-before-finalize-hook
            #'modi/org-capture--remove-auto-org-to-hugo-export-maybe)

  (defun modi/org-capture--add-auto-org-to-hugo-export-maybe ()
    "Function for `org-capture-after-finalize-hook'.
Enable `org-hugo-export-subtree-to-md-after-save'."
    (setq org-hugo-allow-export-after-save t))
  (add-hook 'org-capture-after-finalize-hook
            #'modi/org-capture--add-auto-org-to-hugo-export-maybe))

[Source]


Update (2017/07/23): Updated the above capture template after the date parsing improvement commit c659a6e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment