old headshot of Tobias Weingartner

Toby “Nutty Swiss” Weingartner


Moving to Hugo Static Web Pages

Created 2014-03-16

Over the last 20+ years, I’ve been known to hand-craft all of my own web pages, to the point where I’d be more focused on the “correct” method of structuring every single HTML tag. Yet, during much of this time I’ve been looking for a method of generating web content in a fashion that would allow for faster and easier posting of content. I think I’ve finally found much of what I’m looking for in the Hugo the “Fast and Flexible Static Site Generator”.

Why Hugo?

Over the years, I’ve dabbled in a number of different methods to automatically generate various content for my web presence. At times this included CGI scripts to auto-generate dynamic content. Other the years, the JavaScript support in browsers has progressed to the point where a lot of the server side generation of content is completely unnecessary for a simple web site. Even very involved sites can make do with off-loading the computational parts to the client.

More recently I’ve had a look at Jekyll, but one reason or another, always found it lacking in some way. Also, it seemed to be way too complicated for the simple things that I had in mind. A number of other attempts were made to create a simple Markdown (which I seem to prefer) to HTML translator. Usually these were attempted in Python. Things always seemed to be lacking, or too complex to bother much beyond the mock it up stage.

Over the past year, I’ve been having more and more fun using Go, and when I happened to trip across Hugo, things started to make much more sense. One of the very nice things about Hugo, was that the Markdown processor was an enhanced version that allowed for both YAML front-matter, as well as some extensions to the basic markdown blocks. Beyond this some of the other points that were definite pluses in my book:

These were more than enough to convince me that the time for complete hand crafting of a whole website were behind me. I could keep my old site completely intact (zero edits), and start up blogging again. The rest of the website could be moved to Markdown and/or converted to something more abstract than HTML at some later point.

Supporting Scripts

Hugo provides a static web page generator, as well as the ability to serve a simple web site on the local machine. This makes it very easy to write while you do not have an Internet connection. It is also an easy way to check that the generated web site is working well, allowing you to use the various web browser’s development support.

As I’m a proverbial Unix Neckbeard, I despise not using the tools that are so kindly provided to us in most Unix environments since the inception of all reasonable computing environments (Unix v6). In this case, my web site generation via Hugo and deployment is controlled by a very simple Makefile:

 1#
 2# Do this old-style, using a simple Makefile to generate my web site.  This is
 3# about a simple as it gets people.  Seriously, why do you need more than this?
 4#
 5
 6all: public-home public-tepid
 7
 8server:
 9	hugo server --build-drafts -w
10
11home: public-home
12	rsync -vaz --delete public-home/ weingart@home.tepid.org:htdocs/
13
14public-home: .FORCE
15	hugo --build-drafts -d public-home -b http://home.tepid.org/
16	find public-home -type d -print0 | xargs -0 chmod 755
17	find public-home -type f -print0 | xargs -0 chmod 644
18
19tepid public: public-tepid
20	rsync -vaz --delete public-tepid/ weingart@tepid.org:htdocs/
21
22public-tepid: .FORCE
23	hugo -d public-tepid -b http://tepid.org/
24	find public-tepid -type d -print0 | xargs -0 chmod 755
25	find public-tepid -type f -print0 | xargs -0 chmod 644
26
27.FORCE:
28

Yes, I realize that the “find | xargs chmod” could be replaced with just one appropriate “chmod”. However, the above works on pretty much every single Unix platform (and OSX) that I work on. If you note, this Makefile is about as simple as it gets. Nothing special, no GNUMakefile specifics. It provides:

No need for a complicated Python, Ruby, JS/Node, or other scripting language required to build and deploy. The whole kaboodle is part of a git repository. Even here things are clean. The .gitignore file contents:

public
public-home
public-tepid

Of course, this could be further simplified by using filename patterns. But hey, this is simple enough already, and I don’t envision publishing a bunch more web sites any time soon. Maybe in another lifetime. As they say, at that point I have options.