Hugo

Hugo↗ is one of the most popular open-source static site generators. By default, Hugo will avoid writing the rendered content to disk, preferring to store it in memory.

Usage

Org Mode content is exported as markdown files by ox-hugo . Hugo generates static website content in html from markdown files. myzettel page provides detailed technical explanation on how hugo is used to deliver this site. So Hugo is used in development and for generating html content, which is served using more full featured lighttpd server.

Hugo server must always be started at the site-directory. Otherwise, it’ll error.

prabu@homepc2 /d/d/p/D/o/quickstart (master)> hugo server --buildDrafts --navigateToChanged

By default Web Server will be available at http://localhost:1313/↗ (bind address 127.0.0.1). Press Ctrl+C to stop the server.

Steps to generate html site

When the hugo server is run as follows, it generates html files for all the equivalent md files in ‘‘‘public’’’ folder.

$hugo -D

Remove the older content

By default Hugo does not delete the old content. To ensure that all the older contents are removed, remove the public folder.

prabu@homepc2 /d/d/p/D/o/quickstart (master)> pwd
/data/docs/prabu/Dropbox/org/quickstart
prabu@homepc2 /d/d/p/D/o/quickstart (master)> rm -rf public/

Manual publishing script

Due to repeated issues with syncthing and hugo_watcher service referred below, i went with a manual publishing script has been created as shown below. A custom function to run this script is available in Emacs .

prabu@homepc2 ~> cat /data/myhome/prabu/Dropbox/org/my_hugo_site/scripts/publish_hugo_site.sh
#!/bin/sh
SAVED_KEY=$(grep "SYNCTHING_API_KEY" /home/prabu/.config/syncthing/apikey | cut -d'"' -f2)
Hugo_site="/data/myhome/prabu/Dropbox/org/my_hugo_site"
# Generate the json required to update the graph
python3 "$Hugo_site/scripts/gen_graph.py"
# Build the Site using hugo
/usr/bin/hugo --source "$Hugo_site" --destination "$Hugo_site/public" -D
#Force Syncthing to sync org-Roam folder
curl -s -X POST -H "X-API-Key:$SAVED_KEY" "http://localhost:8384/rest/db/scan?folder=scwmx-w9vj5"
echo "Build complete. Syncthing scan triggered."

Hugo specific gotchas

Hugo specific gotchas are listed in this section.

Enable ugly URL’s.

Edit the the hugo.toml file to enable ugly URL’s.

# To temporarily generete single page static website uncomment below line
# uglyURLs = true

Hugo Shortcodes

When creating content in Org Mode , this tip from https://henryleach.com↗ allowed me to place Hugo shortcodes in the Org-Mode text. Basically the shortcodes has to placed into an HTML export block as can be seen in the index page of this site.

Obsolete

hugo-watcher

A service script named hugo-watcher was created to generate html whenever new content is created from emacs. Disabled this later due to synchronisation issues with syncthing .

  prabu@homepc2 ~> cat /etc/init.d/hugo-watcher
#!/sbin/openrc-run

# Adjust these paths to your actual setup
HUGO_DIR="/data/myhome/prabu/Dropbox/org/my_hugo_site"
HUGO_USER="prabu"
HUGO_GROUP="prabu"

name="Hugo Watcher"
description="Rebuilds Hugo site on file changes"
command="/usr/bin/hugo"
# We use --source and --destination to point to site directory
command_args="--source ${HUGO_DIR} --destination ${HUGO_DIR}/public --watch --cleanDestinationDir -D --quiet"
command_user="${HUGO_USER}:${HUGO_GROUP}"
command_background="yes"
pidfile="/run/hugo-watcher.pid"


depend() {
    need localmount
    after bootmisc
}

Using Rclone with Hugo

Using the rclone + rcx combination, synced the quickstart directory from the local pc to mobile. As mentioned this has been migrated to syncthing .

Source: https://foosel.net/blog/2023-01-21-hugo-meet-android/↗

Resources

I used the following resources when learning about hugo


© Prabu Anand K 2020-2026