LinuxCommandLibrary

hugo

Generate static websites from source files

TLDR

Create a new Hugo site

$ hugo new site [path/to/site]
copy

Create a new Hugo theme (themes may also be downloaded from )
$ hugo new theme [theme_name]
copy

Create a new page
$ hugo new [section_name]/[page_name]
copy

Build a site to the ./public/ directory
$ hugo
copy

Build a site including pages that are marked as a "draft"
$ hugo [[-D|--buildDrafts]]
copy

Build a site on your local IP
$ hugo server --bind [local_ip] --baseURL [http://local_ip]
copy

Build a site to a given directory
$ hugo [[-d|--destination]] [path/to/destination]
copy

Build a site, start up a webserver to serve it, and automatically reload when pages are edited
$ hugo server
copy

SYNOPSIS

hugo [COMMAND] [flags]

Common Commands:
    hugo new <path/to/content.md>
    hugo server [flags]
    hugo build [flags]
    hugo version

PARAMETERS

--source, -s <path>
    Filesystem path to read files relative from. Default is the current working directory.

--destination, -d <path>
    Filesystem path to write files to. Default is 'public/' relative to the source.

--config, -c <file>
    Config file (default is 'config.toml' or 'config.yaml'). Can be specified multiple times for merging.

--baseURL <url>
    Hostname (and path) to the root, e.g., 'https://www.example.com/'.

--theme <name>
    Theme to use (located in /themes/<name>/). Specify multiple themes for cascading.

--verbose
    Enable verbose output during site generation.

--environment, -e <env>
    Build environment (e.g., 'development', 'production'). Affects configuration and build process.

--minify
    Minify HTML, CSS, JS, and JSON files during build (primarily for hugo build).

--cleanDestinationDir
    Remove files from the destination directory before building (primarily for hugo build).

--disableFastRender
    Disables fast render in development, useful for debugging (primarily for hugo server).

--bind <address>
    Address to which the local server will bind (e.g., '0.0.0.0' or 'localhost') (for hugo server).

--port <number>
    Port on which the local server will listen (default is 1313) (for hugo server).

--liveReloadPort <number>
    Port for LiveReload (default is random available port) (for hugo server).

--appendPort
    Appends the port to the baseURL for local development (for hugo server).

--noHTTPCache
    Disable HTTP caching in development (for hugo server).

--printMemoryUsage
    Print memory usage (useful for debugging).

--logFile <path>
    Log file path (if set, logging is enabled to file).

--version
    Print the Hugo version number.

--help, -h
    Show help for a command or subcommand.

DESCRIPTION

Hugo is an open-source static site generator written in Go. It takes content and templates (written in Markdown, HTML, etc.) and transforms them into a collection of static HTML, CSS, and JavaScript files. Unlike traditional content management systems (CMS) that generate pages dynamically on each request, Hugo pre-builds all pages, resulting in incredibly fast load times, enhanced security, and simplified hosting. It is widely used for creating blogs, portfolios, documentation sites, and even complex web applications. Hugo's speed is one of its primary advantages, often building sites in milliseconds. It supports a rich set of features including themes, shortcodes, data files, taxonomies, and LiveReload for development. While it's a command-line tool, its ease of use and powerful features make it a popular choice for developers and content creators alike.

CAVEATS

Hugo's primary caveat for beginners is its templating language (Go's text/template) and content organization. While powerful, it requires some initial learning. Debugging complex template issues can sometimes be challenging. Although it produces static files, understanding web server configuration (e.g., for routing or redirects) might be necessary for deployment. It's not a generic Linux command, but rather an application commonly installed and run on Linux systems.

THEMES AND CONTENT ORGANIZATION

Hugo supports a rich ecosystem of themes that can be easily installed and customized. Content is typically organized in Markdown files within a 'content' directory, reflecting the site's URL structure. It supports archetypes, which are templates for new content, ensuring consistency.

SHORTCODES

Hugo includes 'shortcodes,' which are simple snippets inside Markdown content that Hugo processes during site generation. These allow for embedding complex HTML, custom components, or dynamic content (like YouTube videos or image galleries) without writing raw HTML in content files.

DEPLOYMENT

Once a site is built with hugo build, the generated static files (typically in the 'public/' directory) can be deployed to any web server, static hosting service (e.g., Netlify, Vercel, GitHub Pages), or CDN. This simplicity is a major advantage for scalability and low maintenance.

HISTORY

Hugo was created by Bjørn Erik Pedersen and released in 2013, written entirely in the Go language. Its development was motivated by a desire for a static site generator that was significantly faster than existing solutions, particularly Jekyll, which was (and still is) popular but written in Ruby. From its inception, Hugo focused on speed, simplicity, and performance, quickly gaining traction within the developer community. Its adoption grew significantly as more developers appreciated its rapid build times and robust feature set for a wide array of static web projects, establishing itself as a leading tool in the static site generation landscape.

SEE ALSO

git(1), rsync(1), curl(1), wget(1), make(1), python(1) (for other static site generators like Pelican or Sphinx)

Copied to clipboard