Hugo Basic information about building a website

Common commands, configurations, and directory descriptions

Hugo Common commands

CommandDescriptionExample usage
hugoGenerate a static site and output to the public/directoryhugo --minify
hugo serverStart the development server, default port 1313, real-time preview sitehugo server --bind 0.0.0.0
hugo newCreate a new content file, such as an article or page hugo new post/my-post.md
hugo versionDisplays the current Hugo version informationhugo version
hugo modManage Hugo Modules (modular themes or dependencies)hugo mod init github.com/user/repo
hugo configDisplays the current configuration informationhugo config
hugo envDisplays Hugo environment information (e.g., version, Go version)hugo env
hugo listList content files (e.g., drafts, future articles)hugo list drafts
hugo checkCheck the integrity of the content filehugo check
hugo --helpDisplays Hugo command helphugo --help

Common Options:

  • ‘–watch’: Monitors file changes (‘hugo server’ is enabled by default).
  • ‘–ignoreCache’: ignores the cache and forces a rebuild.
  • ‘–minify’: compresses output files (e.g. HTML, CSS, JS).
  • ‘–debug’: displays debugging information.

Other important content

Config item (commonly used in ‘hugo.yaml’)

CIDescriptionExample value
baseURLThe site root URL, which is used to generate an absolute linkhttps://www.test.com/
languageCodeThe default language code isen-us
themeThe name of the topic usedhugo-theme-stack
titleSite titleMy Blog
permalinksDefines the URL structure of the content typepost: /p/:slug/
outputsSpecify the output formatfor the page type home: ["HTML", "RSS", "JSON"]
paramsCustom parameters for the theme to usesidebar.avatar: /img/avatar.png
menuCustomize the navigation menumain: [{name: "Home", url: "/"}]

Front Matter

FieldDescriptionExample value
titleArticle or page titleMy First Post
dateRelease Date2025-03-28
draftWhether it’s a draft (’true’ is not published)false
tagsTag List["tech", "blog"]
categoriesCategory List["Programming"]
slugCustom part of the URLmy-first-post

Hugo Pipes (Resource Processing)

FeaturesDescriptionExample usage
resources. GetGet resource files (e.g., images, SCSS){{ resources. Get "images/pic.jpg" }}
ResizeResize the image{{ $img. Resize "300x" }}
ToCSSCompile SCSS to CSS`{{ $css := resources. Get “scss/main.scss”
  • Installation Theme:
1git submodule add https://github.com/CaiJimmy/hugo-theme-stack themes/hugo-theme-stack
  • Enable Theme: Set ’theme: hugo-theme-stack’ in ‘hugo.yaml’.

Commonly used Hugo topic tables

Topic nameLinkDescription
PaperMod[github.com/adityatelange/hugo-PaperMod] (https://github.com/adityatelange/hugo-PaperMod)Concise, responsive blog theme that supports dark mode, is easy to read, optimizes user experience, and is suitable for personal blogs
Stack[github.com/CaiJimmy/hugo-theme-stack] (https://github.com/CaiJimmy/hugo-theme-stack)Multi-purpose theme, blog-support, portfolio-supporting, with sidebar and commenting system (like Waline) for tech bloggers
Docsy[github.com/google/docsy] (https://github.com/google/docsy)Designed for technical documentation, multi-language support, integrated search and navigation, suitable for open source project documentation
Anatole[github.com/lxndrblz/anatole] (https://github.com/lxndrblz/anatole)Minimalist two-column theme for blogs and personal portfolios with an elegant, responsive layout
Book[github.com/alex-shpak/hugo-book] (https://github.com/alex-shpak/hugo-book)A concise documentation theme that mimics the style of a book, suitable for tutorials or knowledge base sites.
Hello Friend NG[github.com/rhazdon/hugo-theme-hello-friend-ng] (https://github.com/rhazdon/hugo-theme-hello-friend-ng)Simple blog theme, support dark/light mode switching, focus on typography and reading experience
Mainroad[github.com/vimux/mainroad] (https://github.com/vimux/mainroad)Magazine-style theme with responsive design for informative blogs or news sites
Coder[github.com/luizdepra/hugo-coder] (https://github.com/luizdepra/hugo-coder)A very simple page theme that is suitable for developers to display their bios and projects, and has a fast loading speed
Beautiful Hugo[github.com/halogenica/beautifulhugo] (https://github.com/halogenica/beautifulhugo)Multi-purpose blog theme with support for Disqus comments, social sharing, suitable for personal and professional blogs
Reveal-Hugo[github.com/dzello/reveal-hugo] (https://github.com/dzello/reveal-hugo)Reveal.js-based presentation theme for creating HTML slideshows.

Folder description table in the Hugo root directory and theme directory

Hugo root folder

Folders/FilesDescriptionPrecautions
archetypes/A content template directory that defines the default front matterfor new files such as ‘hugo new’ ‘default.md’ is included by default, and other templates can be customized
assets/The resource file directory, which stores SCSS, images, etc., is processed by Hugo Pipes (e.g., compiling SCSS to CSS)Support needs to be configured in ‘hugo.yaml’ (e.g. ‘assets.dir’).
content/A directory of content files that holds Markdown files, organized by type (e.g. ‘content/post/’ for articles)The file name determines the URL (e.g., ‘my-post.md’ -> ‘/post/my-post/’).
data/A data file directory that holds YAML, JSON, or TOML files for dynamic data (such as navigation menu data). In the template by ‘. Site.Data’ access
layouts/Customize the template directory to override the theme’s default templatePriority is higher than templates of the same name in ’themes/’
public/The generated static site output directory, with the post-build content in thisEach run of ‘hugo’ empties and regenerates the
static/Static file directories, which store images, CSS, JS, etc., are directly copied to the root directory of the site Output directly to ‘public/’, without Hugo processing
themes/A theme directory that stores downloaded or custom themes (e.g. ‘hugo-theme-stack’). Enablevia the ’theme’ configuration
hugo.yamlMaster profile, defining site settings (such as language, theme, URL, etc.)YAML, TOML, JSON formats are supported

Theme directory folder (’themes//’)

Folders/FilesDescriptionPrecautions
archetypes/The theme provides a default content template that uses theIt can be overridden by the ‘archetypes/’ of the root directory
assets/The theme’s resource file directory, which stores SCSS, images, etc., is handled by Hugo PipesUsually contains a style file for the theme (e.g. ‘main.scss’)
layouts/The template directory of the theme, which defines the page rendering logic (e.g., ‘single.html’, ’list.html’). Can be overridden by the ’layouts/’ of the root directory
static/The static file directory of the theme, which stores CSS, JS, images, etc., is directly copied to the root directory of the site Output to ‘public/’, e.g. ‘static/img/’ -> ‘/img/’
data/A data file directory for a topic that provides topic-specific data (such as menu configurations). In the template by ‘. Site.Data’ access
i18n/Internationalized file directory for multilingual translation files (e.g. ’en.yaml’, ‘zh-cn.yaml’)Used to support multilingual sites
README.mdTheme documentation with installation and usage guides It is recommended that you read carefully to understand the configuration requirements
theme.yamlA topic metadata file that defines the topic name, author, minimum version, and so on Used in the Hugo Theme Management System to identify topics

Illustrate:

  • Folders in the root directory and the theme directory function similarly, but the configuration and file priority of the root directory takes precedence over the topic directory.
  • The files in the theme directory are common templates and resources designed for the theme, which can be overwritten or extended by developers through the root directory.

Additional Notes

  1. How to choose a theme:
  • Choose according to your needs: PaperMod or Stack for blogs, Docsy for documents, and Coder for resumes.
  • Check Activity: See when it was last updated and how it was responded to on GitHub.
  1. Folder usage suggestions:
  • Put custom images into ‘static/’ to avoid Hugo processing (e.g. no compression).
  • Store SCSS files in ‘assets/’ to take advantage of Hugo Pipes’ compilation capabilities.
  1. Debugging Tips:**
  • Run ‘hugo server –debug’ to see the file load and render logs.
  • Use ‘hugo –printPathWarnings’ to check for path issues.
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy
Published 7 posts · Total 7.54k words
This site has been running stably for 0 days 00 hours 00 minutes 00 seconds