Setting up the Ox-hugo package to use Org mode with Hugo was much easier than I expected. Here is how I configured it, the workflow for posting with Doom Emacs, and some things to keep in mind.
Installation and configuration
I'm back to using Doom Emacs, so adding Ox-hugo required nothing more than adding the +hugo
flag to :lang org
in the init.el file. Look for org
in init.el, and change it to (org +hugo)
. Ox-hugo has excellent documentation, and I configured it almost exactly the way that was suggested. I was skeptical that having a single Org file that contained every blog post was a good idea, but after two days, it seems to be the way to go. I have a file called "blog.org" in a directory named "content-org" in my hugo project directory. This file has the following settings at the top:
|
|
Then, there is a top-level heading called "Blog Ideas". All other top-level headings are categories. Each second-level heading will be a post under that particular category.
Next, I copied the Org-capture template and made some small modifications. I changed EXPORT_FILE_NAME
to format file names with a date string to match my other post file names. I also included a line with some custom front matter that I usually use, mostly because I know I wouldn't remember how to insert it when I needed it.
Here is the template:
|
|
Workflow
C-c n n
in Doom opens a hydra for Org-capture. Selecting "h" prompts for a post title in the minibuffer. Enter the title, press the return key, and a new Org-mode window opens with the file settings from the capture template. Enter the desired text, then press C-c C-c
to close the window. The post is filed in the site's Org content file under the Blog Ideas section. When ready, move the cursor to a point in the post, and use org-refile to put it in the category that you would like.
Add a file called "dir-locals.el" to the root level of the hugo site directory that has this content:
|
|
Then, as you write your posts, you can preview them at localhost:1313 as you edit them; just start the Hugo server in your terminal application like this:
|
|
Now, every the Org file is saved, it automatically exports the correctly formatted Markdown post to the "content/posts" directory, and Hugo serves up the changed post in your browser.
When the draft is finished, change the TODO
flag in the post title to DONE
, and the date will be updated.
Miscellaneous discoveries
So far, I've found two things to keep in mind. First, headings in the Markdown files will be one level above the headings in the Org file. So, an H2 in the Org file is the post title, sections of the post have a H3 heading. The three stars in the Org file become two octothorpes in the Markdown file.
Second, to specify a CSS class, just put this on the line directly preceding the item needing styling:
|
|
For example, here's how I use my style for philosophical arguments.
|
|
produces this:
-
First premise
-
Second premise
-
Conclusion
Conclusion
Ox-hugo works amazingly well for producing well-formed Hugo Goldmark markdown from an Org mode source file. Since I write nearly everything in Org mode, this enables me to easily use the same material for posts, handouts, and other formats.