Yejun Su

Writing blog with ox-hugo

In the past six months, I keep using Spacemacs to write code and it is very handful. So I wonder how to write articles in Emacs. After searching around, Hugo came into my eyes. Just following the tutorial, a blog is built in less than 5 minutes.

brew install hugo
hugo new site blog
cd blog
git clone https://github.com/spf13/hyde.git themes/hyde
hugo server -t hyde

After that, I installed ox-hugo and begin to write posts in blog/content-org/goofansu.org. Yes, all articles are saved in one org-mode file, you can see the benefits in How I blog: One year of posts in a single org file.

The content in the org file is as following:

#+HUGO_SECTION: posts
#+HUGO_BASE_DIR: ~/src/blog/
#+HUGO_FRONT_MATTER_FORMAT: yaml

* First post
  :PROPERTIES:
  :EXPORT_FILE_NAME: first-post
  :END:

  Hello, this is my first post.

* Second post
  :PROPERTIES:
  :EXPORT_FILE_NAME: second-post
  :END:

  The second post.

After writing the article, use C-c C-e H H to generate the post or C-c C-e H A to generate all posts.

Then you have multiple choices to host the blog, I choose Netlify as it can auto deploy after pushing to GitHub. It is very easy to use, supporting custom domain and SSL certificate for free.

Happy writing :)