An Org Capture template #
If you do not want to manually type the EXPORT_FILE_NAME
for each
new post, here is an example Org Capture template can help:
;; Populates only the EXPORT_FILE_NAME property in the inserted heading.
(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* ((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)
":END:"
"%?\n") ;Place the cursor here finally
"\n")))
(add-to-list 'org-capture-templates
'("h" ;`org-capture' binding + h
"Hugo post"
entry
;; It is assumed that below file is present in `org-directory'
;; and that it has a "Blog Ideas" heading. It can even be a
;; symlink pointing to the actual location of all-posts.org!
(file+olp "all-posts.org" "Blog Ideas")
(function org-hugo-new-subtree-post-capture-template))))
Above capture will auto-insert a heading prefixed with TODO
. With
org-log-done
set to 'time
, on changing the TODO
state to the
DONE
state (C-c C-t
), a Special Property called CLOSED
will be
auto-inserted below the heading. Below is an example.
*** DONE Narrowing the Author column in Magit :org:log:
CLOSED: [2017-12-18 Mon 16:36]
ox-hugo
auto-sets the date
field in the front-matter to the time
stamp in that CLOSED
property.
Alternative way: Export Hugo posts to a Page Bundle organization #
ox-hugo
has first-class support for the Page Bundles style of
content organization, introduced in Hugo v0.32.
If you prefer to have the exported posts to use the Page Bundles style
of content organization, define the same
org-hugo-new-subtree-post-capture-template
as below:
(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* ((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_HUGO_BUNDLE: " fname)
":EXPORT_FILE_NAME: index"
":END:"
"%?\n") ;Place the cursor here finally
"\n")))
Alternative way to set the date
field #
If you prefer to not insert time-stamps using the DONE
-state
switching (i.e. you have org-log-done
at its default value of
nil
), you can explicitly insert the EXPORT_DATE
property too using
the below definition of org-hugo-new-subtree-post-capture-template
instead.
(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")))