Music, Tech, & Art

Blogging from the terminal with doom emacs & hugo on a mac

I’ve been looking to make blogging from org-mode on my mac happen ever since I started using org-mode. Reason being is that while I love learning about all the new frameworks, what I really want is a stupid easy way to write then type a few commands and my writing appear on my site. Now that I’ve repeated the process a few times - installing, configuring, breaking, fixing, breaking again, uninstalling, reinstalling - the way I learn best - I’m happy to share the exact steps I took to get here. These are should be repeatable and simple steps using mostly defaults so there’s less stuff to worry about backing up in case you have to nuke the site from orbit.

First off, I’d like to thank Carl Flippin with this post - https://carlf.io/posts/blogging_with_org_and_hugo/ - who I randomly found online and also happened to work with in the past. So cool when that happens. Thanks Carl for getting me over some issues early on in my process! Hope you’re doing well.

Prerequisites

Emacs Installation & Setup

These install steps assume a blank Mac. If you have Homebrew installed, please skip that step. If you have Emacs installed, you can skip that step, but ideally you’re running the latest version so consider upgrading. The Doom installation step/script intelligently checks for existing Emacs and Doom installs so it doesn’t accidentally write over your custom files.

Note: I don’t put the select/copy/paste buttons in my blog so that you have to exert at least a little effort and therefore maybe thought before blindly copy/pasting commands that do things like install or change system settings. Regular code seems fine in that regard. However, I also don’t think I should go as far as disabling copy/paste entirely. Don’t you hate that?

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Don’t take my word for it though, check on https://brew.sh/.

Install Emacs

This installs within the terminal…it is not a standalone app. The biggest issue I’m having with that right now is that the Terminal.app captures some of the key bindings before they get to emacs. If I find my way around that, I’ll post an update.

brew install emacs

Friend’s don’t let friends copy/paste install commands, check on https://formulae.brew.sh/formula/emacs

Note: I’ve read a lot - and tried a lot - of different emacs installation methods. There’s emacs+ and the cask version for homebrew. I prefer this approach. there’s also a benefit that you can get the following steps set up and remove this flavor of emacs, try the others, and ultimately if you want, like I did, just do another brew install emacs again and everything should be as it was. I’ve done this about 5-6 times and it’s worked every time.

Install Doom

git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.emacs.d
~/.emacs.d/bin/doom install

Check yourself before you wreck yourself: https://github.com/doomemacs/doomemacs#install

Hugo for org mode

This is the one customization you’ll need to do in this otherwise basic default install. In your init.el file in ~/.doom.d/, please change the org under :lang to (org +hugo) and then run:

doom sync

And one last time, confirm here: https://github.com/doomemacs/doomemacs/blob/52bda5f

The process

Once all of this is set up, then there’s some further customization steps and the actual writing and publishing.

  1. Pick a theme for your blog: https://themes.gohugo.io/
  2. Create a repo on Github (or your favorite competitor)
    • Gitlab
    • Netlify
    • Render
  3. Add in this Github actions build and deployment config (or whatever approach makes sense including Netlify): https://gohugo.io/hosting-and-deployment/hosting-on-github/#build-hugo-with-github-action
  4. Make sure your host of choice is ready to receive your pushes and process things on the right branches. The links above should illustrate how to do that.
  5. Write in org-mode
    1. SPC-b-s to save
    2. SPC-m-e-H-H to publish to Hugo
  6. Test locally
    1. hugo server -D
    2. go to http://localhost:1313
  7. Commit
  8. PUSH & PUBLISH
  9. Celebrate!