Hugo Leads the Static Web Revolution

March 13, 2017
Programming

The first time I created a website, back in the mid-1990s, it required manually coding HTML. This later gave way to specialized HTML editors such as the now-defunct Microsoft FrontPage. By the mid-2000s, I used WordPress to create blogs. Indeed, just about every blog that I ghostwrite for professionally uses WordPress.

WordPress is a dynamic content generator. This means it accesses a database to create a page every time a user visits the website. It’s not a bad system, but it can be slow and insecure. After all, an attacker can not only compromise your web server, but also the database or any outside plugins installed on top of WordPress.

Building a Blog From the Terminal

For this (among other reasons) I’ve moved to Hugo, a static content generator, for creating this blog and my professional website. Fortunately the Solus developers think along the same lines, as they recently moved their own public website to Hugo. A “static” content generator is just what it sounds like. You generate the content once on your local computer and then upload it to your web server. There are no databases or other special software requirements. I maintain this blog on a DigitalOcean server running Apache and that’s it.

Hugo is a command-line utility. For example, to create this site I opened a terminal and entered hugo new site opensourcewriter.com. This created a new directory with the basic skeleton for the website. (To see how a Hugo directory looks for a live website, visit my Github repository for this blog.) Hugo does not come with a default theme or template. I don’t know much about CSS or layouts so I downloaded a preexisting theme called Cactus from Hugo’s library and modified it to my needs.

Hugo recognizes Markdown syntax natively, which is handy since I already write my blog posts using Markdown. Hugo also has a built-in web server that lets you see a “live” rendering of your website as you build it. To enable this feature you enter hugo serve from the terminal and point your web browser to localhost:1313.

When your site is ready, enter hugo without any additional arguments. This generates the static website in a separate /public directory, which you can then upload to your server. What I like about this setup is I don’t need to worry about losing my website. If something goes wrong with the web server, I can easily regenerate the site from its source files and upload to it to a new host in less than two minutes.

Need More Information About Hugo?

Hugo is available for multiple platforms, including Solus and most popular Linux distributions, as well as FreeBSD, Windows, and macOS. The creator and lead developer is Steve Francia. He’s licensed Hugo under the Apache License v. 2.0.