Configure Hugo
Configuration file
Create a site configuration file in the root of your project directory, naming it hugo.toml
, hugo.yaml
, or hugo.json
, with that order of precedence.
my-project/
└── hugo.toml
A simple example:
baseURL: https://example.org/
languageCode: en-us
params:
contact:
email: [email protected]
phone: +1 202-555-1212
subtitle: The Best Widgets on Earth
title: ABC Widgets, Inc.
baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'ABC Widgets, Inc.'
[params]
subtitle = 'The Best Widgets on Earth'
[params.contact]
email = '[email protected]'
phone = '+1 202-555-1212'
{
"baseURL": "https://example.org/",
"languageCode": "en-us",
"params": {
"contact": {
"email": "[email protected]",
"phone": "+1 202-555-1212"
},
"subtitle": "The Best Widgets on Earth"
},
"title": "ABC Widgets, Inc."
}
To use a different configuration file when building your site, use the --config
flag:
hugo --config other.toml
Combine two or more configuration files, with left-to-right precedence:
hugo --config a.toml,b.yaml,c.json
Configuration directory
Instead of a single site configuration file, split your configuration by environment, root configuration key, and language. For example:
my-project/
└── config/
├── _default/
│ ├── hugo.toml
│ ├── menus.en.toml
│ ├── menus.de.toml
│ └── params.toml
└── production/
└── params.toml
The root configuration keys are build
, caches
, cascade
, deployment
, frontmatter
, imaging
, languages
, markup
, mediatypes
, menus
, minify
, module
, outputformats
, outputs
, params
, permalinks
, privacy
, related
, security
, segments
, server
, services
, sitemap
, and taxonomies
.
Omit the root key
When splitting the configuration by root key, omit the root key in the given file. For example, these are equivalent:
params:
foo: bar
[params]
foo = 'bar'
{
"params": {
"foo": "bar"
}
}
foo: bar
foo = 'bar'
{
"foo": "bar"
}
Recursive parsing
Hugo parses the config
directory recursively, allowing you to organize the files into subdirectories. For example:
my-project/
└── config/
└── _default/
├── navigation/
│ ├── menus.de.toml
│ └── menus.en.toml
└── hugo.toml
Example
my-project/
└── config/
├── _default/
│ ├── hugo.toml
│ ├── menus.en.toml
│ ├── menus.de.toml
│ └── params.toml
├── production/
│ ├── hugo.toml
│ └── params.toml
└── staging/
├── hugo.toml
└── params.toml
Considering the structure above, when running hugo --environment staging
, Hugo will use every setting from config/_default
and merge staging
’s on top of those.
Let’s take an example to understand this better. Let’s say you are using Google Analytics for your website. This requires you to specify a Google tag ID in your site configuration:
services:
googleAnalytics:
ID: G-XXXXXXXXX
[services]
[services.googleAnalytics]
ID = 'G-XXXXXXXXX'
{
"services": {
"googleAnalytics": {
"ID": "G-XXXXXXXXX"
}
}
}
Now consider the following scenario:
-
You don’t want to load the analytics code when running
hugo server
. -
You want to use different Google tag IDs for your production and staging environments. For example:
G-PPPPPPPPP
for productionG-SSSSSSSSS
for staging
To satisfy these requirements, configure your site as follows:
-
config/_default/hugo.toml
Exclude the
services.googleAnalytics
section. This will prevent loading of the analytics code when you runhugo server
.By default, Hugo sets its
environment
todevelopment
when runninghugo server
. In the absence of aconfig/development
directory, Hugo uses theconfig/_default
directory. -
config/production/hugo.toml
Include this section only:
hugo.services: googleAnalytics: ID: G-PPPPPPPPP
[services] [services.googleAnalytics] ID = 'G-PPPPPPPPP'
{ "services": { "googleAnalytics": { "ID": "G-PPPPPPPPP" } } }
You do not need to include other parameters in this file. Include only those parameters that are specific to your production environment. Hugo will merge these parameters with the default configuration.
By default, Hugo sets its
environment
toproduction
when runninghugo
. The analytics code will use theG-PPPPPPPPP
tag ID. -
config/staging/hugo.toml
Include this section only:
hugo.services: googleAnalytics: ID: G-SSSSSSSSS
[services] [services.googleAnalytics] ID = 'G-SSSSSSSSS'
{ "services": { "googleAnalytics": { "ID": "G-SSSSSSSSS" } } }
You do not need to include other parameters in this file. Include only those parameters that are specific to your staging environment. Hugo will merge these parameters with the default configuration.
To build your staging site, run
hugo --environment staging
. The analytics code will use theG-SSSSSSSSS
tag ID.
Merge configuration from themes
The configuration value for _merge
can be one of:
- none
- No merge.
- shallow
- Only add values for new keys.
- deep
- Add values for new keys, merge existing.
Note that you don’t need to be so verbose as in the default setup below; a _merge
value higher up will be inherited if not set.
build:
_merge: none
caches:
_merge: none
cascade:
_merge: none
deployment:
_merge: none
frontmatter:
_merge: none
httpcache:
_merge: none
imaging:
_merge: none
languages:
_merge: none
en:
_merge: none
menus:
_merge: shallow
params:
_merge: deep
markup:
_merge: none
mediatypes:
_merge: shallow
menus:
_merge: shallow
minify:
_merge: none
module:
_merge: none
outputformats:
_merge: shallow
outputs:
_merge: none
page:
_merge: none
pagination:
_merge: none
params:
_merge: deep
permalinks:
_merge: none
privacy:
_merge: none
related:
_merge: none
security:
_merge: none
segments:
_merge: none
server:
_merge: none
services:
_merge: none
sitemap:
_merge: none
taxonomies:
_merge: none
[build]
_merge = 'none'
[caches]
_merge = 'none'
[cascade]
_merge = 'none'
[deployment]
_merge = 'none'
[frontmatter]
_merge = 'none'
[httpcache]
_merge = 'none'
[imaging]
_merge = 'none'
[languages]
_merge = 'none'
[languages.en]
_merge = 'none'
[languages.en.menus]
_merge = 'shallow'
[languages.en.params]
_merge = 'deep'
[markup]
_merge = 'none'
[mediatypes]
_merge = 'shallow'
[menus]
_merge = 'shallow'
[minify]
_merge = 'none'
[module]
_merge = 'none'
[outputformats]
_merge = 'shallow'
[outputs]
_merge = 'none'
[page]
_merge = 'none'
[pagination]
_merge = 'none'
[params]
_merge = 'deep'
[permalinks]
_merge = 'none'
[privacy]
_merge = 'none'
[related]
_merge = 'none'
[security]
_merge = 'none'
[segments]
_merge = 'none'
[server]
_merge = 'none'
[services]
_merge = 'none'
[sitemap]
_merge = 'none'
[taxonomies]
_merge = 'none'
{
"build": {
"_merge": "none"
},
"caches": {
"_merge": "none"
},
"cascade": {
"_merge": "none"
},
"deployment": {
"_merge": "none"
},
"frontmatter": {
"_merge": "none"
},
"httpcache": {
"_merge": "none"
},
"imaging": {
"_merge": "none"
},
"languages": {
"_merge": "none",
"en": {
"_merge": "none",
"menus": {
"_merge": "shallow"
},
"params": {
"_merge": "deep"
}
}
},
"markup": {
"_merge": "none"
},
"mediatypes": {
"_merge": "shallow"
},
"menus": {
"_merge": "shallow"
},
"minify": {
"_merge": "none"
},
"module": {
"_merge": "none"
},
"outputformats": {
"_merge": "shallow"
},
"outputs": {
"_merge": "none"
},
"page": {
"_merge": "none"
},
"pagination": {
"_merge": "none"
},
"params": {
"_merge": "deep"
},
"permalinks": {
"_merge": "none"
},
"privacy": {
"_merge": "none"
},
"related": {
"_merge": "none"
},
"security": {
"_merge": "none"
},
"segments": {
"_merge": "none"
},
"server": {
"_merge": "none"
},
"services": {
"_merge": "none"
},
"sitemap": {
"_merge": "none"
},
"taxonomies": {
"_merge": "none"
}
}
All configuration settings
archetypeDir
(string
) The directory where Hugo finds archetype files (content templates). Default is archetypes
. Also see Module Mounts Config for an alternative way to configure this directory (from Hugo 0.56).
assetDir
(string
) The directory where Hugo finds asset files used in Hugo Pipes. Default is assets
. Also see Module Mounts Config for an alternative way to configure this directory (from Hugo 0.56).
baseURL
(string
) The absolute URL (protocol, host, path, and trailing slash) of your published site (e.g., https://www.example.org/docs/
).
build
See Configure Build.
buildDrafts
(bool
) Include drafts when building. Default is false
.
buildExpired
(bool
) Include content already expired. Default is false
.
buildFuture
(bool
) Include content with a future publication date. Default is false
.
caches
canonifyURLs
(bool
) See details before enabling this feature. Default is false
.
capitalizeListTitles
New in v0.123.3(bool
) Whether to capitalize automatic list titles. Applicable to section, taxonomy, and term pages. Default is true
. You can change the capitalization style in your site configuration to one of ap
, chicago
, go
, firstupper
, or none
. See details.
cascade
Pass down default configuration values (front matter) to pages in the content tree. The options in site config is the same as in page front matter, see Front Matter Cascade.
cleanDestinationDir
(bool
) When building, removes files from destination not found in static directories. Default is false
.
contentDir
(string
) The directory from where Hugo reads content files. Default is content
. Also see Module Mounts Config for an alternative way to configure this directory (from Hugo 0.56).
copyright
(string
) Copyright notice for your site, typically displayed in the footer.
dataDir
(string
) The directory from where Hugo reads data files. Default is data
. Also see Module Mounts Config for an alternative way to configure this directory (from Hugo 0.56).
defaultContentLanguage
(string
) Content without language indicator will default to this language. Default is en
.
defaultContentLanguageInSubdir
(bool
) Render the default content language in subdir, e.g. content/en/
. The site root /
will then redirect to /en/
. Default is false
.
disableAliases
(bool
) Will disable generation of alias redirects. Note that even if disableAliases
is set, the aliases themselves are preserved on the page. The motivation with this is to be able to generate 301 redirects in an .htaccess
, a Netlify _redirects
file or similar using a custom output format. Default is false
.
disableHugoGeneratorInject
(bool
) Hugo will, by default, inject a generator meta tag in the HTML head on the home page only. You can turn it off, but we would really appreciate if you don’t, as this is a good way to watch Hugo’s popularity on the rise. Default is false
.
disableKinds
(string slice
) Disable rendering of the specified page kinds, any of 404
, home
, page
, robotstxt
, rss
, section
, sitemap
, taxonomy
, or term
.
disableLanguages
See disable a language.
disableLiveReload
(bool
) Disable automatic live reloading of browser window. Default is false
.
disablePathToLower
(bool
) Do not convert the url/path to lowercase. Default is false
.
enableEmoji
(bool
) Enable Emoji emoticons support for page content; see the emoji shortcode quick reference guide. Default is false
.
enableGitInfo
(bool
) Enable .GitInfo
object for each page (if the Hugo site is versioned by Git). This will then update the Lastmod
parameter for each page using the last git commit date for that content file. Default is false
.
enableMissingTranslationPlaceholders
(bool
) Show a placeholder instead of the default value or an empty string if a translation is missing. Default is false
.
enableRobotsTXT
(bool
) Enable generation of robots.txt
file. Default is false
.
environment
(string
) Build environment. Default is production
when running hugo
and development
when running hugo server
. See Configuration directory.
frontmatter
See Front matter Configuration.
hasCJKLanguage
(bool
) If true, auto-detect Chinese/Japanese/Korean Languages in the content. This will make .Summary
and .WordCount
behave correctly for CJK languages. Default is false
.
ignoreCache
(bool
) Ignore the cache directory. Default is false
.
ignoreLogs
(string slice
) A slice of message identifiers corresponding to warnings and errors you wish to suppress. See erroridf
and warnidf
.
ignoreVendorPaths
(string
) Ignore vendored modules that match the given Glob pattern within the _vendor
directory.
imaging
See image processing configuration.
languageCode
(string
) A language tag as defined by RFC 5646. This value is used to populate:
- The
<language>
element in the embedded RSS template - The
lang
attribute of the<html>
element in the embedded alias template - The
og:locale
meta
element in the embedded Open Graph template
When present in the root of the configuration, this value is ignored if one or more language keys exists. Please specify this value independently for each language key.
languages
See Configure Languages.
layoutDir
(string
) The directory that contains templates. Default is layouts
.
markup
See Configure Markup.
mediaTypes
menus
See Menus.
minify
See Configure Minify.
module
Module configuration see module configuration.
newContentEditor
(string
) The editor to use when creating new content.
noBuildLock
(bool
) Don’t create .hugo_build.lock
file. Default is false
.
noChmod
(bool
) Don’t sync permission mode of files. Default is false
.
noTimes
(bool
) Don’t sync modification time of files. Default is false
.
outputFormats
page
See configure page.
pagination
See configure pagination.
panicOnWarning
(bool
) Whether to panic on first WARNING. Default is false
.
permalinks
See Content Management.
pluralizeListTitles
(bool
) Whether to pluralize automatic list titles. Applicable to section pages. Default is true
.
printI18nWarnings
(bool
) Whether to log WARNINGs for each missing translation. Default is false
.
printPathWarnings
(bool
) Whether to log WARNINGs when Hugo publishes two or more files to the same path. Default is false
.
printUnusedTemplates
(bool
) Whether to log WARNINGs for each unused template. Default is false
.
publishDir
(string
) The directory to where Hugo will write the final static site (the HTML files etc.). Default is public
.
refLinksErrorLevel
(string
) When using ref
or relref
to resolve page links and a link cannot be resolved, it will be logged with this log level. Valid values are ERROR
(default) or WARNING
. Any ERROR
will fail the build (exit -1
). Default is ERROR
.
refLinksNotFoundURL
(string
) URL to be used as a placeholder when a page reference cannot be found in ref
or relref
. Is used as-is.
related
See Related Content.
relativeURLs
(bool
) See details before enabling this feature. Default is false
.
removePathAccents
(bool
) Removes non-spacing marks from composite characters in content paths. Default is false
.
content/post/hügó.md → https://example.org/post/hugo/
renderSegments
New in v0.124.0(string slice
) A list of segments to render. If not set, everything will be rendered. This is more commonly set in a CLI flag, e.g. hugo --renderSegments segment1,segment2
. The segment names must match the names in the segments configuration.
sectionPagesMenu
See Menus.
security
See Security Policy.
segments
See Segments.
sitemap
Default sitemap configuration.
summaryLength
(int
) Applicable to automatic summaries, the minimum number of words to render when calling the Summary
method on a Page
object. In this case the Summary
method returns the content, truncated to the paragraph closest to the summaryLength
.
taxonomies
See Configure Taxonomies.
templateMetrics
(bool
) Whether to print template execution metrics to the console. Default is false
. See Template metrics.
templateMetricsHints
(bool
) Whether to print template execution improvement hints to the console. Applicable when templateMetrics
is true
. Default is false
. See Template metrics.
theme
See module configuration for how to import a theme.
themesDir
(string
) The directory where Hugo reads the themes from. Default is themes
.
timeout
(string
) Timeout for generating page contents, specified as a duration or in seconds. Note: this is used to bail out of recursive content generation. You might need to raise this limit if your pages are slow to generate (e.g., because they require large image processing or depend on remote contents). Default is 30s
.
timeZone
(string
) The time zone (or location), e.g. Europe/Oslo
, used to parse front matter dates without such information and in the time
function. The list of valid values may be system dependent, but should include UTC
, Local
, and any location in the IANA Time Zone database.
title
(string
) Site title.
titleCaseStyle
(string
) Default is ap
. See Configure Title Case.
uglyURLs
(bool
) When enabled, creates URL of the form /filename.html
instead of /filename/
. Default is false
.
watch
(bool
) Watch filesystem for changes and recreate as needed. Default is false
.
Configure page
New in v0.133.0These methods on a Page
object navigate to the next or previous page within a page collection, relative to the current page:
Hugo determines the next and previous page by sorting a page collection according to this sorting hierarchy:
Field | Precedence | Sort direction |
---|---|---|
weight |
1 | descending |
date |
2 | descending |
linkTitle |
3 | descending |
path |
4 | descending |
The sort direction in the table above corresponds to these default site configuration values:
page:
nextPrevInSectionSortOrder: desc
nextPrevSortOrder: desc
[page]
nextPrevInSectionSortOrder = 'desc'
nextPrevSortOrder = 'desc'
{
"page": {
"nextPrevInSectionSortOrder": "desc",
"nextPrevSortOrder": "desc"
}
}
To sort all fields in ascending order:
page:
nextPrevInSectionSortOrder: asc
nextPrevSortOrder: asc
[page]
nextPrevInSectionSortOrder = 'asc'
nextPrevSortOrder = 'asc'
{
"page": {
"nextPrevInSectionSortOrder": "asc",
"nextPrevSortOrder": "asc"
}
}
Configure build
The build
configuration section contains global build-related configuration options.
build:
buildStats:
disableClasses: false
disableIDs: false
disableTags: false
enable: false
cacheBusters:
- source: (postcss|tailwind)\.config\.js
target: (css|styles|scss|sass)
noJSConfigInAssets: false
useResourceCacheWhen: fallback
[build]
noJSConfigInAssets = false
useResourceCacheWhen = 'fallback'
[build.buildStats]
disableClasses = false
disableIDs = false
disableTags = false
enable = false
[[build.cacheBusters]]
source = '(postcss|tailwind)\.config\.js'
target = '(css|styles|scss|sass)'
{
"build": {
"buildStats": {
"disableClasses": false,
"disableIDs": false,
"disableTags": false,
"enable": false
},
"cacheBusters": [
{
"source": "(postcss|tailwind)\\.config\\.js",
"target": "(css|styles|scss|sass)"
}
],
"noJSConfigInAssets": false,
"useResourceCacheWhen": "fallback"
}
}
- buildStats New in v0.115.1
- When enabled, creates a
hugo_stats.json
file in the root of your project. This file contains arrays of theclass
attributes,id
attributes, and tags of every HTML element within your published site. Use this file as data source when removing unused CSS from your site. This process is also known as pruning, purging, or tree shaking.
Exclude class
attributes, id
attributes, or tags from hugo_stats.json
with the disableClasses
, disableIDs
, and disableTags
keys.
Due to the nature of partial server builds, new HTML entities are added while the server is running, but old values will not be removed until you restart the server or run a regular hugo
build.
- cachebusters
- See Configure Cache Busters
- noJSConfigInAssets
- Turn off writing a
jsconfig.json
into your/assets
folder with mapping of imports from running js.Build. This file is intended to help with intellisense/navigation inside code editors such as VS Code. Note that if you do not usejs.Build
, no file will be written. - useResourceCacheWhen
- When to use the cached resources in
/resources/_gen
for PostCSS and ToCSS. Valid values arenever
,always
andfallback
. The last value means that the cache will be tried if PostCSS/extended version is not available.
Configure cache busters
New in v0.112.0The build.cachebusters
configuration option was added to support development using Tailwind 3.x’s JIT compiler where a build
configuration may look like this:
build:
buildStats:
enable: true
cachebusters:
- source: assets/watching/hugo_stats\.json
target: styles\.css
- source: (postcss|tailwind)\.config\.js
target: css
- source: assets/.*\.(js|ts|jsx|tsx)
target: js
- source: assets/.*\.(.*)$
target: $1
[build]
[build.buildStats]
enable = true
[[build.cachebusters]]
source = 'assets/watching/hugo_stats\.json'
target = 'styles\.css'
[[build.cachebusters]]
source = '(postcss|tailwind)\.config\.js'
target = 'css'
[[build.cachebusters]]
source = 'assets/.*\.(js|ts|jsx|tsx)'
target = 'js'
[[build.cachebusters]]
source = 'assets/.*\.(.*)$'
target = '$1'
{
"build": {
"buildStats": {
"enable": true
},
"cachebusters": [
{
"source": "assets/watching/hugo_stats\\.json",
"target": "styles\\.css"
},
{
"source": "(postcss|tailwind)\\.config\\.js",
"target": "css"
},
{
"source": "assets/.*\\.(js|ts|jsx|tsx)",
"target": "js"
},
{
"source": "assets/.*\\.(.*)$",
"target": "$1"
}
]
}
}
When buildStats
New in v0.115.1 is enabled, Hugo writes a hugo_stats.json
file on each build with HTML classes etc. that’s used in the rendered output. Changes to this file will trigger a rebuild of the styles.css
file. You also need to add hugo_stats.json
to Hugo’s server watcher. See Hugo Starter Tailwind Basic for a running example.
- source
- A regexp matching file(s) relative to one of the virtual component directories in Hugo, typically
assets/...
. - target
- A regexp matching the keys in the resource cache that should be expired when
source
changes. You can use the matching regexp groups fromsource
in the expression, e.g.$1
.
Configure server
This is only relevant when running hugo server
, and it allows to set HTTP headers during development, which allows you to test out your Content Security Policy and similar. The configuration format matches Netlify’s with slightly more powerful Glob matching:
server:
headers:
- for: /**
values:
Content-Security-Policy: script-src localhost:1313
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
[server]
[[server.headers]]
for = '/**'
[server.headers.values]
Content-Security-Policy = 'script-src localhost:1313'
Referrer-Policy = 'strict-origin-when-cross-origin'
X-Content-Type-Options = 'nosniff'
X-Frame-Options = 'DENY'
X-XSS-Protection = '1; mode=block'
{
"server": {
"headers": [
{
"for": "/**",
"values": {
"Content-Security-Policy": "script-src localhost:1313",
"Referrer-Policy": "strict-origin-when-cross-origin",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"X-XSS-Protection": "1; mode=block"
}
}
]
}
}
Since this is “development only”, it may make sense to put it below the development
environment:
headers:
- for: /**
values:
Content-Security-Policy: script-src localhost:1313
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
[[headers]]
for = '/**'
[headers.values]
Content-Security-Policy = 'script-src localhost:1313'
Referrer-Policy = 'strict-origin-when-cross-origin'
X-Content-Type-Options = 'nosniff'
X-Frame-Options = 'DENY'
X-XSS-Protection = '1; mode=block'
{
"headers": [
{
"for": "/**",
"values": {
"Content-Security-Policy": "script-src localhost:1313",
"Referrer-Policy": "strict-origin-when-cross-origin",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"X-XSS-Protection": "1; mode=block"
}
}
]
}
You can also specify simple redirects rules for the server. The syntax is again similar to Netlify’s.
Note that a status
code of 200 will trigger a URL rewrite, which is what you want in SPA situations, e.g:
redirects:
- force: false
from: /myspa/**
status: 200
to: /myspa/
[[redirects]]
force = false
from = '/myspa/**'
status = 200
to = '/myspa/'
{
"redirects": [
{
"force": false,
"from": "/myspa/**",
"status": 200,
"to": "/myspa/"
}
]
}
Setting force=true
will make a redirect even if there is existing content in the path. Note that before Hugo 0.76 force
was the default behavior, but this is inline with how Netlify does it.
404 server error page
Hugo will, by default, render all 404 errors when running hugo server
with the 404.html
template. Note that if you have already added one or more redirects to your server configuration, you need to add the 404 redirect explicitly, e.g:
redirects:
- from: /**
status: 404
to: /404.html
[[redirects]]
from = '/**'
status = 404
to = '/404.html'
{
"redirects": [
{
"from": "/**",
"status": 404,
"to": "/404.html"
}
]
}
With a multilingual site, define the redirect for the default content language last:
defaultContentLanguage: en
defaultContentLanguageInSubdir: false
redirects:
- from: /fr/**
status: 404
to: /fr/404.html
- from: /**
status: 404
to: /404.html
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = false
[[redirects]]
from = '/fr/**'
status = 404
to = '/fr/404.html'
[[redirects]]
from = '/**'
status = 404
to = '/404.html'
{
"defaultContentLanguage": "en",
"defaultContentLanguageInSubdir": false,
"redirects": [
{
"from": "/fr/**",
"status": 404,
"to": "/fr/404.html"
},
{
"from": "/**",
"status": 404,
"to": "/404.html"
}
]
}
If you are serving the default content language from a subdirectory:
defaultContentLanguage: en
defaultContentLanguageInSubdir: true
redirects:
- from: /fr/**
status: 404
to: /fr/404.html
- from: /**
status: 404
to: /en/404.html
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = true
[[redirects]]
from = '/fr/**'
status = 404
to = '/fr/404.html'
[[redirects]]
from = '/**'
status = 404
to = '/en/404.html'
{
"defaultContentLanguage": "en",
"defaultContentLanguageInSubdir": true,
"redirects": [
{
"from": "/fr/**",
"status": 404,
"to": "/fr/404.html"
},
{
"from": "/**",
"status": 404,
"to": "/en/404.html"
}
]
}
Configure title case
By default, Hugo follows the capitalization rules published in the Associated Press Stylebook when creating automatic section titles, and when transforming strings with the strings.Title
function.
Change this behavior by setting titleCaseStyle
in your site configuration to any of the values below:
- ap
- Use the capitalization rules published in the Associated Press Stylebook.
- chicago
- Use the capitalization rules published in the Chicago Manual of Style.
- go
- Capitalize the first letter of every word.
- firstupper
- Capitalize the first letter of the first word.
- none
- Disable transformation of automatic section titles, and disable the transformation performed by the
strings.Title
function. This is useful if you would prefer to manually capitalize section titles as needed, and to bypass opinionated theme usage of thestrings.Title
function.
Configuration environment variables
- DART_SASS_BINARY
- (
string
) The absolute path to the Dart Sass executable. By default, Hugo searches for the executable in each of the paths in thePATH
environment variable. - HUGO_ENVIRONMENT
- (
string
) Overrides the default environment, typically one ofdevelopment
,staging
, orproduction
.
- HUGO_FILE_LOG_FORMAT
- (
string
) A format string for the file path, line number, and column number displayed when reporting errors, or when calling thePosition
method from a shortcode or Markdown render hook. Valid tokens are:file
,:line
, and:col
. Default is:file::line::col
.
- HUGO_MEMORYLIMIT
- (
int
) The maximum amount of system memory, in gigabytes, that Hugo can use while rendering your site. Default is 25% of total system memory. - HUGO_NUMWORKERMULTIPLIER
- (
int
) The number of workers used in parallel processing. Default is the number of logical CPUs.
Configure with environment variables
In addition to the 3 configuration options already mentioned, configuration key-values can be defined through operating system environment variables.
For example, the following command will effectively set a website’s title on Unix-like systems:
$ env HUGO_TITLE="Some Title" hugo
This is really useful if you use a service such as Netlify to deploy your site. Look at the Hugo docs Netlify configuration file for an example.
If you are using snake_cased variable names, the above will not work. Hugo determines the delimiter to use by the first character after HUGO
. This allows you to define environment variables on the form HUGOxPARAMSxAPI_KEY=abcdefgh
, using any allowed delimiter.
Ignore content and data files when rendering
To exclude specific files from the content
, data
, and i18n
directories when rendering your site, set ignoreFiles
to one or more regular expressions to match against the absolute file path.
To ignore files ending with .foo
or .boo
:
ignoreFiles:
- \.foo$
- \.boo$
ignoreFiles = ['\.foo$', '\.boo$']
{
"ignoreFiles": [
"\\.foo$",
"\\.boo$"
]
}
To ignore a file using the absolute file path:
ignoreFiles:
- ^/home/user/project/content/test\.md$
ignoreFiles = ['^/home/user/project/content/test\.md$']
{
"ignoreFiles": [
"^/home/user/project/content/test\\.md$"
]
}
Configure front matter
Configure dates
Dates are important in Hugo, and you can configure how Hugo assigns dates to your content pages. You do this by adding a frontmatter
section to your hugo.toml
.
The default configuration is:
frontmatter:
date:
- date
- publishdate
- pubdate
- published
- lastmod
- modified
expiryDate:
- expirydate
- unpublishdate
lastmod:
- :git
- lastmod
- modified
- date
- publishdate
- pubdate
- published
publishDate:
- publishdate
- pubdate
- published
- date
[frontmatter]
date = ['date', 'publishdate', 'pubdate', 'published', 'lastmod', 'modified']
expiryDate = ['expirydate', 'unpublishdate']
lastmod = [':git', 'lastmod', 'modified', 'date', 'publishdate', 'pubdate', 'published']
publishDate = ['publishdate', 'pubdate', 'published', 'date']
{
"frontmatter": {
"date": [
"date",
"publishdate",
"pubdate",
"published",
"lastmod",
"modified"
],
"expiryDate": [
"expirydate",
"unpublishdate"
],
"lastmod": [
":git",
"lastmod",
"modified",
"date",
"publishdate",
"pubdate",
"published"
],
"publishDate": [
"publishdate",
"pubdate",
"published",
"date"
]
}
}
If you, as an example, have a non-standard date parameter in some of your content, you can override the setting for date
:
frontmatter:
date:
- myDate
- :default
[frontmatter]
date = ['myDate', ':default']
{
"frontmatter": {
"date": [
"myDate",
":default"
]
}
}
The :default
is a shortcut to the default settings. The above will set .Date
to the date value in myDate
if present, if not we will look in date
,publishDate
, lastmod
and pick the first valid date.
In the list to the right, values starting with “:” are date handlers with a special meaning (see below). The others are just names of date parameters (case insensitive) in your front matter configuration. Also note that Hugo have some built-in aliases to the above: lastmod
=> modified
, publishDate
=> pubdate
, published
and expiryDate
=> unpublishdate
. With that, as an example, using pubDate
as a date in front matter, will, by default, be assigned to .PublishDate
.
The special date handlers are:
:fileModTime
- Fetches the date from the content file’s last modification timestamp.
An example:
frontmatter:
lastmod:
- lastmod
- :fileModTime
- :default
[frontmatter]
lastmod = ['lastmod', ':fileModTime', ':default']
{
"frontmatter": {
"lastmod": [
"lastmod",
":fileModTime",
":default"
]
}
}
The above will try first to extract the value for .Lastmod
starting with the lastmod
front matter parameter, then the content file’s modification timestamp. The last, :default
should not be needed here, but Hugo will finally look for a valid date in :git
, date
and then publishDate
.
:filename
- Fetches the date from the content file’s file name. For example,
2018-02-22-mypage.md
will extract the date2018-02-22
. Also, ifslug
is not set,mypage
will be used as the value for.Slug
.
An example:
frontmatter:
date:
- :filename
- :default
[frontmatter]
date = [':filename', ':default']
{
"frontmatter": {
"date": [
":filename",
":default"
]
}
}
The above will try first to extract the value for .Date
from the file name, then it will look in front matter parameters date
, publishDate
and lastly lastmod
.
:git
- This is the Git author date for the last revision of this content file. This will only be set if
--enableGitInfo
is set orenableGitInfo = true
is set in site configuration.
Configure minify
See the tdewolff/minify project page for details.
Default configuration:
minify:
disableCSS: false
disableHTML: false
disableJS: false
disableJSON: false
disableSVG: false
disableXML: false
minifyOutput: false
tdewolff:
css:
inline: false
keepCSS2: true
precision: 0
html:
keepComments: false
keepConditionalComments: false
keepDefaultAttrVals: true
keepDocumentTags: true
keepEndTags: true
keepQuotes: false
keepSpecialComments: true
keepWhitespace: false
templateDelims:
- ""
- ""
js:
keepVarNames: false
precision: 0
version: 2022
json:
keepNumbers: false
precision: 0
svg:
inline: false
keepComments: false
precision: 0
xml:
keepWhitespace: false
[minify]
disableCSS = false
disableHTML = false
disableJS = false
disableJSON = false
disableSVG = false
disableXML = false
minifyOutput = false
[minify.tdewolff]
[minify.tdewolff.css]
inline = false
keepCSS2 = true
precision = 0
[minify.tdewolff.html]
keepComments = false
keepConditionalComments = false
keepDefaultAttrVals = true
keepDocumentTags = true
keepEndTags = true
keepQuotes = false
keepSpecialComments = true
keepWhitespace = false
templateDelims = ['', '']
[minify.tdewolff.js]
keepVarNames = false
precision = 0
version = 2022
[minify.tdewolff.json]
keepNumbers = false
precision = 0
[minify.tdewolff.svg]
inline = false
keepComments = false
precision = 0
[minify.tdewolff.xml]
keepWhitespace = false
{
"minify": {
"disableCSS": false,
"disableHTML": false,
"disableJS": false,
"disableJSON": false,
"disableSVG": false,
"disableXML": false,
"minifyOutput": false,
"tdewolff": {
"css": {
"inline": false,
"keepCSS2": true,
"precision": 0
},
"html": {
"keepComments": false,
"keepConditionalComments": false,
"keepDefaultAttrVals": true,
"keepDocumentTags": true,
"keepEndTags": true,
"keepQuotes": false,
"keepSpecialComments": true,
"keepWhitespace": false,
"templateDelims": [
"",
""
]
},
"js": {
"keepVarNames": false,
"precision": 0,
"version": 2022
},
"json": {
"keepNumbers": false,
"precision": 0
},
"svg": {
"inline": false,
"keepComments": false,
"precision": 0
},
"xml": {
"keepWhitespace": false
}
}
}
}
Configure file caches
Since Hugo 0.52 you can configure more than just the cacheDir
. This is the default configuration:
caches:
assets:
dir: :resourceDir/_gen
maxAge: -1
getcsv:
dir: :cacheDir/:project
maxAge: -1
getjson:
dir: :cacheDir/:project
maxAge: -1
getresource:
dir: :cacheDir/:project
maxAge: -1
images:
dir: :resourceDir/_gen
maxAge: -1
misc:
dir: :cacheDir/:project
maxAge: -1
modules:
dir: :cacheDir/modules
maxAge: -1
[caches]
[caches.assets]
dir = ':resourceDir/_gen'
maxAge = -1
[caches.getcsv]
dir = ':cacheDir/:project'
maxAge = -1
[caches.getjson]
dir = ':cacheDir/:project'
maxAge = -1
[caches.getresource]
dir = ':cacheDir/:project'
maxAge = -1
[caches.images]
dir = ':resourceDir/_gen'
maxAge = -1
[caches.misc]
dir = ':cacheDir/:project'
maxAge = -1
[caches.modules]
dir = ':cacheDir/modules'
maxAge = -1
{
"caches": {
"assets": {
"dir": ":resourceDir/_gen",
"maxAge": -1
},
"getcsv": {
"dir": ":cacheDir/:project",
"maxAge": -1
},
"getjson": {
"dir": ":cacheDir/:project",
"maxAge": -1
},
"getresource": {
"dir": ":cacheDir/:project",
"maxAge": -1
},
"images": {
"dir": ":resourceDir/_gen",
"maxAge": -1
},
"misc": {
"dir": ":cacheDir/:project",
"maxAge": -1
},
"modules": {
"dir": ":cacheDir/modules",
"maxAge": -1
}
}
}
You can override any of these cache settings in your own hugo.toml
.
The keywords explained
- cacheDir
- (
string
) See Configure cacheDir. - project
- (
string
) The base directory name of the current Hugo project. This means that, in its default setting, every project will have separated file caches, which means that when you dohugo --gc
you will not touch files related to other Hugo projects running on the same PC. - resourceDir
- (
string
) This is the value of theresourceDir
configuration option. - maxAge
- (
string
) This is the duration before a cache entry will be evicted, -1 means forever and 0 effectively turns that particular cache off. Uses Go’stime.Duration
, so valid values are"10s"
(10 seconds),"10m"
(10 minutes) and"10h"
(10 hours). - dir
- (
string
) The absolute path to where the files for this cache will be stored. Allowed starting placeholders are:cacheDir
and:resourceDir
(see above).
Configure cacheDir
This is the directory where Hugo by default will store its file caches. See Configure File Caches.
This can be set using the cacheDir
config option or via the OS environment variable HUGO_CACHEDIR
.
If this is not set, Hugo will use, in order of preference:
- If running on Netlify:
/opt/build/cache/hugo_cache/
. This means that if you run your builds on Netlify, all caches configured with:cacheDir
will be saved and restored on the next build. For other CI vendors, please read their documentation. For an CircleCI example, see this configuration. - In a
hugo_cache
directory below the OS user cache directory as defined by Go’s os.UserCacheDir. On Unix systems, this is$XDG_CACHE_HOME
as specified by basedir-spec-latest if non-empty, else$HOME/.cache
. On MacOS, this is$HOME/Library/Caches
. On Windows, this is%LocalAppData%
. On Plan 9, this is$home/lib/cache
. New in v0.116.0 - In a
hugo_cache_$USER
directory below the OS temp dir.
If you want to know the current value of cacheDir
, you can run hugo config
, e.g: hugo config | grep cachedir
.
Configure HTTP cache
New in v0.127.0Note that this configuration is currently only relevant when using the resources.GetRemote function.
The caching in Hugo is layered:
- Dynacache
- A in memory LRU cache that gets evicted on changes, Cache Buster matches and in low memory situations.
- HTTP Cache
- Enables HTTP cache behavior (RFC 9111) for remote resources. This works best for resources with properly set up HTTP cache headers. The HTTP cache uses the file cache to store and serve cached resources.
- File Cache
- See file cache.
The default HTTP cache disables everything:
HTTPCache:
cache:
for:
excludes:
- '**'
includes: null
polls:
- disable: true
for:
excludes: null
includes:
- '**'
high: 0s
low: 0s
[HTTPCache]
[HTTPCache.cache]
[HTTPCache.cache.for]
excludes = ['**']
[[HTTPCache.polls]]
disable = true
high = '0s'
low = '0s'
[HTTPCache.polls.for]
includes = ['**']
{
"HTTPCache": {
"cache": {
"for": {
"excludes": [
"**"
],
"includes": null
}
},
"polls": [
{
"disable": true,
"for": {
"excludes": null,
"includes": [
"**"
]
},
"high": "0s",
"low": "0s"
}
]
}
}
- caching
- Enabled RFC 9111 cache behavior for a configured set of resources. Stale resources will be refreshed from the file cache even if their configured TTL isn’t reached.
- polling
- Enables polling for a set of resources. Note that you can enable polling for resources even if HTTP caching is disabled. This setting is only used when in watch mode (e.g.
hugo server
). When a changed resource is detected, that change triggers a rebuild of pages using that resource.
Configure segments
New in v0.124.0- Each segment consists of zero or more
exclude
filters and zero or moreinclude
filters. - Each filter consists of one or more field Glob matchers.
- Each filter in a section (
exclude
orinclude
) is ORed together, each matcher in a filter is ANDed together.
The fields that can be used in the filters are:
- path
- The logical page path.
- lang
- The page language.
- kind
- The kind of the page.
- output
- The output format of the page.
It is recommended to put coarse grained filters (e.g. for language and output format) in the excludes section, e.g.:
segments:
segment1:
excludes:
- lang: n*
- lang: en
output: rss
includes:
- kind: '{home,term,taxonomy}'
- path: '{/docs,/docs/**}'
[segments]
[segments.segment1]
[[segments.segment1.excludes]]
lang = 'n*'
[[segments.segment1.excludes]]
lang = 'en'
output = 'rss'
[[segments.segment1.includes]]
kind = '{home,term,taxonomy}'
[[segments.segment1.includes]]
path = '{/docs,/docs/**}'
{
"segments": {
"segment1": {
"excludes": [
{
"lang": "n*"
},
{
"lang": "en",
"output": "rss"
}
],
"includes": [
{
"kind": "{home,term,taxonomy}"
},
{
"path": "{/docs,/docs/**}"
}
]
}
}
}
With the above you can render only the pages in segment1
by configuring the renderSegments or setting the --renderSegments
flag:
hugo --renderSegments segment1
Multiple segments can be configured, and the --renderSegments
flag can take a comma separated list of segments.
Some use cases for this feature:
- Splitting builds of big sites.
- Enable faster builds during development by only rendering a subset of the site.
- Partial rebuilds, e.g. render the home page and the “news section” every hour, render the entire site once a week.
- Render only e.g. the JSON output format to push to e.g. a search index.