Building an Org Mode Website: Part 4
- Published: July 16, 2025
Keeping the Configuration With the Website
One difficulty with using the Org Mode publish function is that the configuration for how to export the org files into a website is an entry (or entries) in org-publish-project-alist. In order for the configuration to persist across Emacs sessions, we usually set the configuration in the init.el file (or one of its equivalents) that Emacs loads on every startup. This ends up separating the website configuration from its content.
I normally keep the source for my websites in git repository that is used across multiple computers depending on where and how I am working at that moment. Though my Emacs config is also synced in a similar way, it would be easy for the website configuration in init.el to get out of sync with the website content. It also makes it difficult to create a branch in git to work on a website change outside of the main updates. There would be a single configuration for all branches even if the website change required a change in the configuation.
Custom publishing function
To work around this limitation, I have created a custom function in my init.el. This function does the following steps:
- Saves the current org-publish-project-alist value
- Loads a file from the current directory that sets the org-publish-project variable
- Starts the org-publish function
- Restores the original value of org-publish-project-alist
The function is listed below. The function requires that there be a 'org-publish-project.el' file in the current directory. Ideally that file is in the root folder of your website source. To use the function, I navigate in Dired to the website root folder and run the function.
Function: ks/org-publish
(defun ks/org-publish () (interactive) "A function to use a org-publish-alist from the current directory" (setq ks/store-current-alist org-publish-project-alist) (if (file-exists-p (expand-file-name "org-publish-project.el")) (progn (load (expand-file-name "org-publish-project.el")) (call-interactively 'org-publish))) (setq org-publish-project-alist ks/store-current-alist))
NOTE: THIS FUNCTION HAS NO SAFEGUARDS! As written it will run anything that is in the org-publish-project.el file. If the org-publish-project.el file does not exist the function will abort, but it will also run a file by that name if it exists in whatever Emacs currently thinks is the working directory.
I may eventually make function a little more robust and error-proof and publish it separately in a public git repo, but for now use carefully!