Spacemacs and Hugo made easy

March 6, 2018

I am almost done with my new setup. This all starts with refactoring my web site (Hugo backend), archiving and reorganizing my text-based workflow, and finally blogging again after several months IDLE.

The only pieces missing are: I need a more efficient way to interact with Hugo from Emacs (I mean without having to go to a terminal to create new post or preview my site); I also need to change the CSS a bit and add an Archive page to see all the posts.

In this post, I will talk about the first part: writing and publishing directly using Emacs. There are a couple of blog posts that deal with this, with people suggesting a publishing workflow entirely based on org-mode, for example org mode for blogging (h/t Irreal). This approach relies on a single file “where each heading corresponds to one post, and headings could then be exported to individual markdown files”, and I am not very happy with this idea.

I know that one can write in org-mode instead of Markdown. Indeed, “Hugo 0.19 brings native Emacs Org-mode content support (#1483).” I also found that there exists an Org exporter backend, ox-hugo. The installation appears quite easy, especially for Spacemacs users. Compared to the preceding solution, it allows us to work with one org file for each post.

Then I discovered that there is an Emacs major mode for managing Hugo blogs, namely emacs-easy-hugo (available on MELPA). It allows to write in Markdown or with org-mode directly. The corresponding format is chosen based on file extension. At first glance, it looks like it does not play well with Spacemacs but it works perfectly, pending minor tweaks that are now well documented on the GitHUb repository.

Overall, I like this setup. I can (1) easily manage all my posts, much like when I am using Deft, (2) choose between Markdown (for blog posts) or Org (for single web page) format, (3) access most of hugo options without having to switch to a terminal. Moreover, easy-hugo let me select pictures from Hugo static/img directory (M-x easy-hugo-image), or from my ~/Pictures folder (M-x easy-hugo-put-image), where I store all my screenshots.1

♪ Laura Veirs • Year of Meteors

  1. I use this little bash script together with a Launch Agent that is watching my Desktop for new screenshots. New screenshots are automagically moved to my ~/Pictures folder with a more convenient name yyy-mm-dd-hh-mm-ss.png, which serves as a unique ID and that I can safely move to Hugo static/img directory afterward. ↩︎

See Also

» lost+found 2016 » A text-based workflow for taking note » Migrating to Hugo » lost+found 2015 » Why I am still using Emacs