About

This site is build with Hugo which is a static site generator using markdown. The usual way of doing github action with hugo is using the actions-hugo workflow. Since I’m using org-mode for literally everything, it’s only natural that I also use it for blogging.

Figure 1: Deployment to github pages

Figure 1: Deployment to github pages

Setup

Create a script for exporting org-files to markdown

We need to be able to export the org-mode files into markdown format. Depending on how the files are organized, we need to have a function that could export them. Here I’m using per file layout1.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-refresh-contents)
(package-initialize)
(package-install 'ox-hugo)
(require 'ox-hugo)

(defun export-org-files ()
  "Export files to hugo markdown."
  (interactive)
  (dolist (f (append (file-expand-wildcards "content-org/**/*.org")))
    (with-current-buffer (find-file f)
      (org-hugo-export-to-md))))
Code Snippet 1: build.el

Things to note:

  • The packages needed by Emacs for exporting:
  • Here my org-mode files are placed in ./content-org/ with each posts in their own subdirectory,
  • so the function required for exporting is org-hugo-export-to-md, it should be different when using another type of layout.

Create a makefile

This will be called by the github action workflow.

1
2
3
4
5
.PHONY: all

all:
    @echo "Publishing org files..."
    emacs -Q --batch --load scripts/build.el --funcall export-org-files
Code Snippet 2: Makefile

Things to note:

  • This script is calling the emacs-lisp file we’ve created earlier.

Create GIthub action workflow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: hugo CI
on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - name: checkout repository
        uses: actions/checkout@v4
        with:
          submodules: true
          fetch-depth: 0

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true

      - name: install emacs
        uses: purcell/setup-emacs@master
        with:
          version: snapshot

      - name: export all org-mode files
        run: make all

      - name: build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: github.ref == 'refs/heads/main'
        with:
          github_token: ${{ secrets.PERSONAL_TOKEN }}
          publish_dir: ./public
Code Snippet 3: deploy.yml

Things to note:

  • secrets.PERSONAL_TOKEN must be set within the repository settings in Github.
Figure 2: secrets and variable

Figure 2: secrets and variable