1f8ddb8a52 content: clarify resources front matter key descriptions e064ab8528 content: Add deprecation badges to module config page 727ca5563a github: Add push trigger to lint workflow 64dd5c9886 content: Fix typo c5bc6b6515 github: Fix lint workflow faec0c3a0a github: Combine linting actions into a single workflow 06112aeaf2 theme: Miscellaneous template edits 75d4902270 theme: Format templates with gotmplfmt fec2e2a67e content: Document that the language code in a file name must be lowercase 9dbd841ba6 content: Document the src attribute in the Page Resources metadata reference fd3ffef985 content: Fix "build from source" instructions for Windows af4c9cd4d7 content: Miscellaneous edits 408d8b2f0a content: Miscellaneous edits e8804afe6e content: Fix typo d98276be30 content: Updates for v0.161.0 01b1f8fa12 content: Note merge limitation for slice configuration values d2b18f0c8d content: Document page matcher usage for cascading values 45e5bd9ab3 content: Update Cloudflare Worker host/deploy guide b83726b89a content: Document fallback rendering for fenced code blocks 8f1eeb42bc content: Update reference for source code shortcode e8da56303b content: Add gotmplfmt to list of VS Code extensions 950fabbfd6 content: Update FAQ on feature availability error 6411146d24 content: Update quick start guide 38cc39fd51 content: Add Hugo Shortcodes to list of VS Code extensions 72d98b107b content: Misc updates to get validators to pass 9fb0e1ca35 Add a paragraph about sec boundaries e6abf5644f content: Improve syntax highlighting documentation c06193bd1a content: Update go-i18n package reference ce58fef945 Hugo 0.161.1 c7e0f63385 content: Fix package references 7f15fb3bf9 data: Regen docshelper 7483d53b55 Update HUGO_VERSION to 0.161.0 c4abcdb45f security: Add a bullet point about "pragmatic defaults" 3cd7492862 content: Improve explanation of mount removal in module configurations 4099f07bb9 content: Update GitHub Pages workflow example a6c9853a58 content: Fix typo e6f79a938b Update netlify.toml abda3d6659 content: Update Action versions in GitHub Pages workflow example 55dd288fa9 content: Add GitCMS to front-ends tools list 21081f6d49 content: Remove outdated new-in badges b2ec263884 content: Update version references 825e0b8ea9 One more CSS var adjustment 85f95a899b Adjust css.Build var docs a little df48288002 content: Updates for v0.160.0 a82a9b9797 Update HUGO_VERSION to 0.160.0 1155747dc4 content: Improve CSS processing feature description f6ce893974 content: Add css.Build to features 67b8ed1198 content: Fix typos 0f62a67863 content: Fix typo dbb42aed4a content: Document the deploy edition 549f30f933 content: De-emphasize references to the extended edition 8f5c9782d4 content: Add Pages CMS to front-ends documentation b2bfc3af48 Update HUGO_VERSION to 0.159.2 3793156fc5 content: Fix typos bacd4824ef content: Specify function namespace in example 7f2dc0d40a Regen docs.yml 65a851f731 Update HUGO_VERSION to 0.159.1 ce05fe3fc0 content: Adjust variable references in build script examples 8a04f9fe64 content: Improve hosting build script examples 67962ce05c content: Link to Codeberg Pages 404 handling fd248f57ed content: Identify esbuild as the foundation for build functions 62f02879fd content: Remove outdated content 553c407f9e content: Miscellaneous corrections 77e2cad088 content: Add new-in badge for usePackageJSON 0746e1e621 Add a page on using npm dependencies in Hugo Modules 8824850f5c Update HUGO_VERSION to 0.159.0 git-subtree-dir: docs git-subtree-split: 1f8ddb8a5230518f07c50b4b03cba3cae21081c4
5.6 KiB
title, description, categories, keywords, weight, aliases
| title | description | categories | keywords | weight | aliases | ||||
|---|---|---|---|---|---|---|---|---|---|
| Basic usage | Use the command-line interface (CLI) to perform basic tasks. | 20 |
|
Test your installation
After installing Hugo, test your installation by running:
hugo version
Display available commands
To see a list of the available commands and flags:
hugo help
To get help with a subcommand, use the --help flag. For example:
hugo server --help
Build your project
To build your project, cd into your project directory and run:
hugo build
The hugo build command builds your project, publishing the files to the public directory. To publish your project to a different directory, use the --destination flag or set publishDir in your project configuration.
Note
Hugo does not clear the
publicdirectory before building your project. Existing files are overwritten, but not deleted. This behavior is intentional to prevent the inadvertent removal of files that you may have added to thepublicdirectory after the build.Depending on your needs, you may wish to manually clear the contents of the
publicdirectory before every build.
Draft, future, and expired content
Hugo allows you to set draft, date, publishDate, and expiryDate in the front matter of your content. By default, Hugo will not publish content when:
- The
draftvalue istrue - The
dateis in the future - The
publishDateis in the future - The
expiryDateis in the past
Note
Hugo publishes descendants of draft, future, and expired node pages. To prevent publication of these descendants, use the
cascadefront matter field to cascade build options to the descendant pages.
You can override the default behavior when running hugo build or hugo server with command line flags:
hugo build --buildDrafts # or -D
hugo build --buildExpired # or -E
hugo build --buildFuture # or -F
Although you can also set these values in your project configuration, it can lead to unwanted results unless all content authors are aware of, and understand, the settings.
Note
As noted above, Hugo does not clear the
publicdirectory before building your project. Depending on the current evaluation of the four conditions above, after the build yourpublicdirectory may contain extraneous files from a previous build.A common practice is to manually clear the contents of the
publicdirectory before each build to remove draft, expired, and future content.
Develop and test your site
To view your site while developing layouts or creating content, cd into your project directory and run:
hugo server
The hugo server command builds your site and serves your pages using a minimal HTTP server. When you run hugo server it will display the URL of your local site:
Web Server is available at http://localhost:1313/
While the server is running, it watches your project directory for changes to assets, configuration, content, data, layouts, translations, and static files. When it detects a change, the server rebuilds your site and refreshes your browser using LiveReload.
Most Hugo builds are so fast that you may not notice the change unless you are looking directly at your browser.
LiveReload
While the server is running, Hugo injects JavaScript into the generated HTML pages. The LiveReload script creates a connection from the browser to the server via web sockets. You do not need to install any software or browser plugins, nor is any configuration required.
Automatic redirection
When editing content, if you want your browser to automatically redirect to the page you last modified, run:
hugo server --navigateToChanged
Deploy your site
Note
As noted above, Hugo does not clear the
publicdirectory before building your project. Manually clear the contents of thepublicdirectory before each build to remove draft, expired, and future content.
When you are ready to deploy your site, run:
hugo
This builds your site, publishing the files to the public directory. The directory structure will look something like this:
public/
├── categories/
│ ├── index.html
│ └── index.xml <-- RSS feed for this section
├── posts/
│ ├── my-first-post/
│ │ └── index.html
│ ├── index.html
│ └── index.xml <-- RSS feed for this section
├── tags/
│ ├── index.html
│ └── index.xml <-- RSS feed for this section
├── index.html
├── index.xml <-- RSS feed for the site
└── sitemap.xml
In a simple hosting environment, where you typically ftp, rsync, or scp your files to the root of a virtual host, the contents of the public directory are all that you need.
Most of our users deploy their sites to a CI/CD platform, where a push1 to their remote Git repository triggers a build and deployment. Learn more in the host and deploy section.
-
The Git repository contains the entire project directory, typically excluding the
publicdirectory because the site is built after the push. ↩︎