Hi there,

Today, we will looking at installation of hugo - a static site generator and deployment on OpenBSD server

Installing hugo

Tested and deployed hugo generated site pages on OpenBSD 6.3-stable and at the time of writing this blog, hugo is not available in the ports on OpenBSD 6.3, so, we will be proceeding with installation from source.

Dependencies

  • go
  • mage (make alternative for go)

Following are the steps to install mage from the source on OpenBSD 6.3:

go get github.com/magefile/mage
cd ${GOPATH:-$HOME/go}/src/github.com/magefile/mage
go run bootstrap.go
then, execute the following command to copy the mage binary to /usr/bin/ directory:
doas cp $HOME/go/bin/mage /usr/bin/
Download hugo from git:
go get -d github.com/gohugoio/hugo
cd ${GOPATH:-$HOME/go}/src/github.com/gohugoio/hugo
mage vendor
mage install

Now, execute the following command to copy the hugo binary to /usr/bin/ directory:

doas cp $HOME/go/bin/hugo /usr/bin/

Generating and hosting static pages using hugo locally

[xxx@localhost ~]$ hugo new site ~/example-site
Congratulations! Your new Hugo site is created in /home/feddy/example-site.

Just a few more steps and you're ready to go:

1\. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/, or
   create your own with the "hugo new theme " command.
2\. Perhaps you want to add some content. You can add single files
   with "hugo new /.".
3\. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.
[xxx@localhost ~]$
[xxx@localhost ~]$ cd example-site/
[xxx@localhost example-site]$ git clone https://github.com/halogenica/beautifulhugo.git themes/beautifulhugo
Cloning into 'themes/beautifulhugo'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 1786 (delta 4), reused 8 (delta 3), pack-reused 1768
Receiving objects: 100% (1786/1786), 2.45 MiB | 288.00 KiB/s, done.
Resolving deltas: 100% (1053/1053), done.
[xxx@localhost example-site]$

then, edit the config.toml file and add line theme = “beautifulhugo” and start hugo server: hugo server -D or can also use hugo “-t” option from the command line, hugo server -t beautifulhugo open the link in browser to access the geenrated web-page, http://localhost:1313/ Adding the first post using hugo hugo new posts/my-first-post.md for full the documentation please visit Hugo documentation

Deployment of the newly generated static site on OpenBSD server:

deploy the static website after creation of the static site, though, found several blogs and posts about using git and git-hook script for deployment and I feel following is an easy option after creating posts, make sure that draft = true has been removed from the posts which are going to publish.

To genenrate pubish pages: rm -rf public/ && hugo then use scp or rsync to copy the contents of the public/ directory to the server, here, it is OpenBSD Then start the web server, and enjoy :)

If something is missing or not correct, please feel free to update