4

Every time I publish html files in org-mode, I clutter up my directory with them.

Is there a way to automatically export html files to a specific directory?

I've tried this solution: https://stackoverflow.com/questions/9559753/emacs-org-mode-export-to-another-directory#9560534

However there is no org-export-publishing-directory in my emacs. I'm not sure why.

Thanks for any help.

1
  • I was trying to figure out the same thing and for now, I am sticking with putting #+EXPORT_FILE_NAME: /export/location/file.html, which is enough for my needs. May 22 at 18:49

1 Answer 1

5

A long time ago there was an export backend for org that defined org-export-publishing-directory, but it disappeared when the export code was rewritten. It turns out that the export functions can still do it with a little help. Here's how I set things up by advising an org function:

;; Add advice to let me set a different directory for the exported
;; files. Usually I do this with a directory-local variable for a
;; project, like this:
;; ((org-mode . ((my/org-export-dir "export-dir"))))

(defun my/set-org-export-directory (orig-fun extension
                                    &optional subtreep pub-dir)
  "Advice function to set export directory for `org-export-output-file-name'.
Set `my/org-export-dir' to specify the desired export directory."
  (let ((pub-dir (or pub-dir
                     (and (boundp 'my/org-export-dir)
                          my/org-export-dir))))
    (apply orig-fun extension subtreep pub-dir nil)))

(advice-add 'org-export-output-file-name
            :around #'my/set-org-export-directory)

Of course, this is fragile with respect to changes in the org-mode code!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.