When we are working on a website, we like to examine the resulting pages immediately. We can start Hugo in server mode to generate a local preview in no time.
A command like the following in the root of a project starts the Hugo server:
hugo server -D --minify --navigateToChanged
The HTML pages are rendered into memory and the site is served under http://localhost:1313 by default.
-Dlets Hugo include drafted files. All files created with
hugo neware usually configured as drafts, using
draft: truein the front-matter. When a Markdown file is ready for publishing, we need to remove this entry or change it to
--minifytells Hugo to remove unnecessary whitespace from the resulting code.
--navigateToChangedtells the server to relay the page of the last changed file to the browser. As soon as we save a file the corresponding page pops up in the browser.
Some editors are saving our work so fast by default, that nearly every keystroke leads to a new file version and the regeneration of the corresponding page. When we are in the process of changing sensitive content like front-matter parameters this can easily bring down Hugo’s server, because Hugo can’t process inconsistent files. Then we have to restart the server, which is not a big deal, but gets annoying after a while. It’s better to set the auto-save delay to a bigger value, which lets us save consistent file versions manually.
To generate a new Markdown file, we go to the root folder of our project and use a command like
hugo new blog/first.md
The new file is created in the folder content/blog. It already contains a front-matter section with some reasonable entries or placeholders to start with.
description parameters are mandatory for Perplex as they are for many other themes. The pages headers, page sorting and the navigation depends on them.
The title is guessed from the file name and the date from the moment we ran the
hugo new command.1
The Markdown content begins after the front-matter. Hugo will update our site in the browser as soon as we save a changed version of the file. When we make mistakes, Hugo will display a descriptive error message on its console and in the browser (if Hugo’s server is providing the pages).
Show all the steps described above
The templates for the file generation with
hugo newreside in the folder archetypes. ↩︎