Org-mode/ox-hugo/capture template issues

:weary:

I am using ox-hugo to write blog posts.

I am using a single org file to keep all blog posts in subsections (which is recommended by ox-hugo docs), as well as keeping my notes and todos.

My org file layout is as follows:

* Personal
** Notes
** Tasks
** Blog Posts
* Work
** Notes
** Tasks

I am using a capture template function (from the ox-hugo docs) to quick-capture blog posts.

The function I am using is as follows:

(defun grim/org-hugo-new-subtree-post-capture-template ()
  (let* ((date (format-time-string (org-time-stamp-format  :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
                 ,(concat ":EXPORT_HUGO_CUSTOM_FRONT_MATTER: "  ":tags something :subtitle booyea :featured false :categories abc :highlight true ")
                 ":END:"
                 "%?\n")          ;Place the cursor here
               "\n")))

My capture templates are as follows:

(after! org

  (setq org-capture-templates
        '(
          ("p" "Personal Task" entry (file+olp org-default-notes-file "Personal" "Tasks") "*** TODO %T %?       :personal:")
          ("P" "Personal Note" entry (file+olp org-default-notes-file "Personal" "Notes") "*** %U       :personal:\n%?")
          ("w" "Work Task" entry (file+olp org-default-notes-file "Work" "Tasks") "*** TODO %T %?       :work:")
          ("W" "Work Note" entry (file+olp org-default-notes-file "Work" "Notes") "*** %U       :work:\n%?")
          ("h" "Blog Post" entry (file+olp org-default-notes-file "Personal" "Blog Posts") (function grim/org-hugo-new-subtree-post-capture-template))
          )
        org-log-done 'time
        org-todo-keywords '((sequence "TODO" "IN-PROGRESS" "WAITING" "|" "DONE" "CANCELED"))
        org-startup-folded t))

The capture template works well. It places the post properly under the Personal/Blog Posts headlines as described in the olp section of the capture template.

The PROBLEM is that my blog posts are written in org-mode (as is the point of ox-hugo), and i frequently use asterisks for sections and subsections in the blog posts.

If i were to write an org-mode blog post with the title of ‘TEST POST’ and the following body text:

* welcome to my blog
** this is my first post

This should be entered into the org file as follows:

* Personal
** Notes
** Tasks
** Blog Posts
*** TEST POST
**** welcome to my blog
***** this is my first post
* Work
** Notes
** Tasks

instead, it does insert into the proper area of the org file, breaking all of the subsections and headlines as follows:

* Personal
** Notes
** Tasks
** Blog Posts
*** TEST POST
* welcome to my blog
** this is my first post
* Work
** Notes
** Tasks

as you can see, this breaks the org file layout, and makes it impossible to use the C-c C-e H H hugo subsection export, as the hierarchy of the file is mangled.

The todo/title of the capture-template entry is placed in the correct location, with the correct level (even though there is only one asterisk in the capture template), but any following are reverted back to level 0.

This topic was automatically closed after 90 days. New replies are no longer allowed.