Triaxx Web Log

Hugo

Abstract

Hugo is an open-source static website generator. It is written in Go and uses Markdown file format as input to produce static HTML website.

Initialization

Site

hugo new project <path>
cd <path>
cat > hugo.toml << EOF
baseURL = 'https://triaxx.io/'
languageCode = 'fr-FR'
title = 'Triaxx Web Log'
EOF

Theme

A theme is mandatory to build sites.

hugo new theme <name>
echo "theme = '<name>' >> hugo.toml

A example menu can be copied from themes/<name>/hugo.toml:

rm -f themes/<name>/hugo.toml
cat >> hugo.toml < EOF
[menus]
  [[menus.main]]
    name = 'Home'
    pageRef = '/'
    weight = 10

  [[menus.main]]
    name = 'Posts'
    pageRef = '/posts'
    weight = 20

  [[menus.main]]
    name = 'Tags'
    pageRef = '/tags'
    weight = 30
EOF

Some directories are for example purpose and can be safely removed.

for dir in archetypes content static ; do
  rm -rf themes/<name>/${dir}
done

Content

hugo new content <path>

where <path> can be posts/<filename>.md because the theme assumes a /posts subdirectory.

A tag can be added to the TOML front matter of the markdown file.

Service

Publishing

A post at <path> can be published if its draft field is set to false:

sed -i -e 's|draft = true|draft = false|' <path>

Rendering

A local server can be started listening on port 1313:

hugo server

Deployment

Static site can be deployed with rsync:

CTL_PATH=.ssh-tunnel
HOST:=www.triaxx.io
HOSTPORT:=22
PORT:=2222
REMOTE_PATH:=/var/www/hugo/public
TUNNEL_HOST:=hv.triaxx.io
USER=rsync

deploy:
	hugo build && \
		rsync --archive \
		      --compress \
		      --delete \
		      --verbose \
		      --rsh='ssh -p $(HOSTPORT)' \
		      public/ $(USER)@$(HOST):$(REMOTE_PATH)

# Deployment rule for IPv4-only networks
deploy4:
	ssh -f -M -N -S $(CTL_PATH) -L $(PORT):$(HOST):$(HOSTPORT) $(TUNNEL_HOST)
	hugo build && \
		rsync --archive \
		      --compress \
		      --delete \
		      --verbose \
		      --rsh='ssh -p $(PORT)' \
		      public/ $(USER)@localhost:$(REMOTE_PATH)
	ssh -S $(CTL_PATH) -O exit $(TUNNEL_HOST)
Tags: