ox-hugo
ox-hugo copied to clipboard
Headline levels are mangled when exporting a capture template into an existing org file
I am having an issue with exporting to a file from the capture template in the docs.
everything basically works, my capture template works, I enter the post title, I get the blog editing window, it saves to the right place.
the issue is with HOW it saves the subtree...
I am exporting to a file where I have all of my blog posts as subsections or subtrees under a heading. I call the file as such:
("h" "Blog Post" entry (file+olp org-default-notes-file "Personal" "Blog Posts") (function grim/org-hugo-new-subtree-post-capture-template))
the file I am writing to (grim.org) has everything in it.. like this:
* Personal
* * Todo
* * Notes
* * Blog Posts
* Work
* * Todo
* * Notes
so I am setting the capture/save location with file+olp, and everything gets placed in the correct location when I C-c C-c the capture window.
The problem When I write a blog post, I obviously use org-mode format, which means my headlines or subsections start with an asterisk. so if I were to write a new blog post with the capture template using a title of 'NEW BLOG POST' (for this example) like this:
* this is my blog post
here is some text about the blog post
* * this is another section
my org file is butchered after saving the capture, like this:
* Personal
* * Todo
* * Notes
* * Blog Posts
* * * NEW BLOG POST
* this is my blog post
here is some text about the blog post
* * this is another section
* Work
* * Todo
* * Notes
the very top headline (the title of the blog post) gets inserted in my grim.org file with the proper headline level, but anything in the blog post body does not.
then, when going to the specific blog post subtree, I cannot use C-c C-e H H
to export to a blog post, because the headline hierarchy is mangled.
is there a way to automatically make the headlines of my org-capture-template start at level 4?
thank you kindly for your help
for more clarity here is my code:
(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: "))
(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")
"\n")))
(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))