reddit / emacs

Splitting a tree into multiple pages on export/publish

ExistentialTowel · 2022-08-03 16:27
I would like to have a file `posts.org` and inside of it I would have multiple "posts" such as: * A post Some content * Another post some other content The default result of `org-publish-all` is to build a single `posts.html`. Is there a way to split up top-level headings into their own html pages? One thought I had was to write an elisp function that does this prior to the publishing function being called, but I'd rather avoid that solution as it's another step in the build process.
your_sweetpea · 2022-08-03 20:08
I'd look at `ox-hugo` and write your own implementation of what it does, which is using org-map-entries and calling the publish function on each of them with a filename you generate in some way (presumably just the title of the subheading?) EDIT: something like (defun org-html-export-all-subtrees () (interactive) (org-map-entries (lambda () (when (= (outline-level) 1) (let ((filename (org-link-display-format (nth 4 (org-heading-components))))) (org-export-to-file 'html (concat org-html-root filename ".html") nil 'subtree)))))) That's just me writing off the top of my head though, and I haven't tested it. I'm sure I've made some error somewhere You would have to set `org-html-root` or prompt for it or something like that though, and you would probably want to do some formatting on the filename (or even grab EXPORT\_FILE\_NAME or see if there's an ox function that I just don't know about)