There's no way to just configure this, but you can modify the behavior without too much work if you want.
There's a function called org-export-output-file-name
which computes the file name for the export. You can write a modification for this function using defadvice
.
I've not tested it specifically, but something like this may get you started:
(defadvice org-export-output-file-name (around export-to-directories activate)
"alters the org export process to create a subdirectory for each exported org file"
(let* ((visited-file (buffer-file-name (buffer-base-buffer)))
(dir-name (file-name-sans-extension (file-name-nondirectory visited-file))))
(setf pub-dir
(concat (file-name-as-directory (or pub-dir "."))
dir-name))
ad-do-it))
org-export-output-file-name
takes an argument called pub-dir
which contains the directory to publish to; this is generally taken from your project configuration. This advice sets pub-dir
to a new value before calling ad-do-it
to call the original function.
Of course, even if I haven't made any other mistakes, there's still one potential problem here. The original org-export-output-file-name
is still going to use the current file name again when constructing the output file name. For example, when exporting the file foo.org
this advised function is going to return the file name ./foo/foo.html
. For your use-case, it sounds like a better value would be ./foo/index.html
.
If the code had been written to pass the file name in as an argument this would be easy to fix; just override that argument. It seems to me that the only way to fix this is to modify the return value as well as the arguments:
(defadvice org-export-output-file-name (around export-to-directories activate)
"alters the org export process to create a subdirectory for each exported org file"
(let* ((visited-file (buffer-file-name (buffer-base-buffer)))
(dir-name (file-name-sans-extension (file-name-nondirectory visited-file))))
(setf pub-dir
(concat (file-name-as-directory (or pub-dir "."))
dir-name))
ad-do-it
(setf ad-return-value
(replace-regexp-in-string (regexp-quote (concat dir-name "." extension))
(concat "index." extension)
ad-return-value))))
It's also possible that you could handle that with a rewrite rule (or similar) in your web server config.