Building and Exploring Hugo’s Output

When you run hugo server, it generates your content in memory. To write Hugo’s output to disk, run the hugo command with no options, like this:

 $ ​​hugo
 ...
  | EN
 +------------------+----+
  Pages | 5
  Paginator pages | 0
  Non-page files | 0
  Static files | 0
  Processed images | 0
  Aliases | 0
  Sitemaps | 1
  Cleaned | 0
 
 Total in 21 ms

This generates the pages for your site in a new directory named public. If you look at that directory’s contents, you’ll see these files and directories:

 public/
 ├── about
 │   └── index.html
 ├── categories
 │   └── index.xml
 ├── index.html
 ├── index.xml
 ├── sitemap.xml
 └── tags
  └── index.xml

Hugo has created the HTML files for your home page and the About page, as well as the file index.xml, which is an RSS feed for your site. It’s also created a sitemap file, as well as RSS feeds for your site’s tags and categories. You’re not doing anything with those right now, so you can ignore them.

This public folder is your entire static site. To host it, you could upload the contents of the public folder to your web server, or upload it to your CDN. You’ll explore how to put your site live in Chapter 8, Deploying the Site.

Hugo doesn’t clean up the public folder. If you were to remove some pages or rename them, you would need to delete the generated versions from the public folder as well. It’s much easier to delete the entire public folder whenever you generate the site:

 $ ​​rm​​ ​​-r​​ ​​public​​ ​​&&​​ ​​hugo

Alternatively, use Hugo’s --cleanDestinationDir argument:

 $ ​​hugo​​ ​​--cleanDestinationDir

You can tell Hugo to minify the files it generates. This process removes whitespace characters, resulting in smaller file sizes that will make the site download faster for your visitors. To do this, use the --minify option:

 $ ​​hugo​​ ​​--cleanDestinationDir​​ ​​--minify

The public/index.html now looks something like this:

 <!doctype html>​<html lang=​en-us​><head><meta name=​generator
 content=​"Hugo 0.68.3"​><meta charset=​utf-8​><title>Brian's Portfolio</title>
 </head><body><h1>Brian's Portfolio</h1><p>This is my portfolio.</p>
 <p>On this site, you&rsquo;ll find</p><ul><li>My biography</li>
 <li>My projects</li><li>My résumé</li></ul></body></html>

All the indentation and line breaks are removed. As a result, this file contains fewer bytes, which means it’ll transfer faster when you eventually deploy the files to production.