diff options
Diffstat (limited to 'docs/content/en/getting-started/configuration.md')
-rw-r--r-- | docs/content/en/getting-started/configuration.md | 495 |
1 files changed, 216 insertions, 279 deletions
diff --git a/docs/content/en/getting-started/configuration.md b/docs/content/en/getting-started/configuration.md index 5e861759b..3ce0077ba 100644 --- a/docs/content/en/getting-started/configuration.md +++ b/docs/content/en/getting-started/configuration.md @@ -15,61 +15,117 @@ aliases: [/overview/source-directory/,/overview/configuration/] ## Configuration file -Hugo uses the `hugo.toml`, `hugo.yaml`, or `hugo.json` (if found in the -site root) as the default site 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. -The user can choose to override that default with one or more site configuration files using the command-line `--config` switch. +```text +my-project/ +└── hugo.toml +``` + +{{% note %}} +With v0.109.0 and earlier the basename of the site configuration file was `config` instead of `hugo`. You can use either, but should transition to the new naming convention when practical. +{{% /note %}} -Examples: +A simple example: -```txt -hugo --config debugconfig.toml -hugo --config a.toml,b.toml,c.toml +{{< code-toggle file=hugo >}} +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' +{{< /code-toggle >}} + +To use a different configuration file when building your site, use the `--config` flag: + +```sh +hugo --config other.toml +``` + +Combine two or more configuration files, with left-to-right precedence: + +```sh +hugo --config a.toml,b.yaml,c.json ``` {{% note %}} -Multiple site configuration files can be specified as a comma-separated string to the `--config` switch. +See the specifications for each file format: [TOML], [YAML], and [JSON]. + +[TOML]: https://toml.io/en/latest +[YAML]: https://yaml.org/spec/ +[JSON]: https://datatracker.ietf.org/doc/html/rfc7159 {{% /note %}} -## hugo.toml vs config.toml +## Configuration directory -In Hugo 0.110.0 we changed the default configuration base file name to `hugo`, e.g. `hugo.toml`. We will still look for `config.toml` etc., but we recommend you eventually rename it (but you need to wait if you want to support older Hugo versions). The main reason we're doing this is to make it easier for code editors and build tools to identify this as a Hugo configuration file and project. +Instead of a single site configuration file, split your configuration by [environment], root configuration key, and language. For example: -{{< new-in 0.110.0 >}} +[environment]: /getting-started/glossary/#environment -## Configuration directory +```text +my-project/ +└── config/ + ├── _default/ + │ ├── hugo.toml + │ ├── menus.en.toml + │ ├── menus.de.toml + │ └── params.toml + ├── production/ + │ ├── hugo.toml + │ └── params.toml + └── staging/ + ├── hugo.toml + └── params.toml +``` -In addition to using a single site configuration file, one can use the `configDir` directory (default to `config/`) to maintain easier organization and environment specific settings. +The root configuration keys are `build`, `caches`, `cascade`, `deployment`, `frontmatter`, `imaging`, `languages`, `markup`, `mediatypes`, `menus`, `minify`, `module`, `outputformats`, `outputs`, `params`, `permalinks`, `privacy`, `related`, `security`, `server`, `services`, `sitemap`, and `taxonomies`. -- Each file represents a configuration root object, such as `params.toml` for `[Params]`, `menu(s).toml` for `[Menu]`, `languages.toml` for `[Languages]` etc... -- Each file's content must be top-level, for example: +### Omit the root key -{{< code-toggle file="hugo" copy=false >}} -[Params] - foo = "bar" +When splitting the configuration by root key, omit the root key in the given file. For example, these are equivalent: + +{{< code-toggle file=hugo >}} +[params] +foo = 'bar' {{< /code-toggle >}} -{{< code-toggle file="params" copy=false >}} -foo = "bar" +{{< code-toggle file=params >}} +foo = 'bar' {{< /code-toggle >}} -- Each directory holds a group of files containing settings unique to an environment. -- Files can be localized to become language specific. +### Recursive parsing -```txt -├── config -│ ├── _default -│ │ ├── hugo.toml -│ │ ├── languages.toml -│ │ ├── menus.en.toml -│ │ ├── menus.zh.toml -│ │ └── params.toml -│ ├── production -│ │ ├── hugo.toml -│ │ └── params.toml -│ └── staging -│ ├── hugo.toml -│ └── params.toml +Hugo parses the `config` directory recursively, allowing you to organize the files into subdirectories. For example: + +```text +my-project/ +└── config/ + └── _default/ + ├── navigation/ + │ ├── menus.de.toml + │ └── menus.en.toml + └── hugo.toml +``` + +### Example + +```text +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. @@ -144,356 +200,272 @@ Note that you don't need to be so verbose as in the default setup below; a `_mer ## All configuration settings -The following is the full list of Hugo-defined variables. Users may choose to override those values in their site configuration file(s). - -### archetypeDir - -**Default value:** "archetypes" - -The directory where Hugo finds archetype files (content templates). {{% module-mounts-note %}} +###### archetypeDir -### assetDir +(`string`) The directory where Hugo finds archetype files (content templates). Default is `archetypes`. {{% module-mounts-note %}} -**Default value:** "assets" +###### assetDir -The directory where Hugo finds asset files used in [Hugo Pipes](/hugo-pipes/). {{% module-mounts-note %}} +(`string`) The directory where Hugo finds asset files used in [Hugo Pipes](/hugo-pipes/). Default is `assets`. {{% module-mounts-note %}} -### baseURL +###### baseURL -The absolute URL (protocol, host, path, and trailing slash) of your published site (e.g., `https://www.example.org/docs/`). +(`string`) The absolute URL (protocol, host, path, and trailing slash) of your published site (e.g., `https://www.example.org/docs/`). -### build +###### build -See [Configure Build](#configure-build) +See [Configure Build](#configure-build). -### buildDrafts (false) +###### buildDrafts -**Default value:** false +(`bool`) Include drafts when building. Default is `false`. -Include drafts when building. +###### buildExpired -### buildExpired +(`bool`) Include content already expired. Default is `false`. -**Default value:** false +###### buildFuture -Include content already expired. +(`bool`) Include content with publishdate in the future. Default is `false`. -### buildFuture +###### caches -**Default value:** false +See [Configure File Caches](#configure-file-caches). -Include content with publishdate in the future. - -### caches - -See [Configure File Caches](#configure-file-caches) - -### cascade +###### cascade Pass down 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](/content-management/front-matter#front-matter-cascade). {{% note %}} For a website in a single language, define the `[[cascade]]` in [Front Matter](/content-management/front-matter#front-matter-cascade). For a multilingual website, define the `[[cascade]]` in [Site Config](../../getting-started/configuration/#cascade). -To remain consistent and prevent unexpected behaviour, do not mix these strategies. +To remain consistent and prevent unexpected behavior, do not mix these strategies. {{% /note %}} -### canonifyURLs - -**Default value:** false - -Enable to turn relative URLs into absolute. See [details](/content-management/urls/#canonical-urls). - -### cleanDestinationDir - -**Default value:** false - -When building, removes files from destination not found in static directories. - -### contentDir - -**Default value:** "content" - -The directory from where Hugo reads content files. {{% module-mounts-note %}} - -### copyright - -**Default value:** "" - -Copyright notice for your site, typically displayed in the footer. - -### dataDir - -**Default value:** "data" - -The directory from where Hugo reads data files. {{% module-mounts-note %}} - -### defaultContentLanguage +###### canonifyURLs -**Default value:** "en" +(`bool`) Enable to turn relative URLs into absolute. Default is `false`. See [details](/content-management/urls/#canonical-urls). -Content without language indicator will default to this language. +###### cleanDestinationDir -### defaultContentLanguageInSubdir +(`bool`) When building, removes files from destination not found in static directories. Default is `false`. -**Default value:** false +###### contentDir -Render the default content language in subdir, e.g. `content/en/`. The site root `/` will then redirect to `/en/`. +(`string`) The directory from where Hugo reads content files. Default is `content`. {{% module-mounts-note %}} -### disableAliases +###### copyright -**Default value:** false +(`string`) Copyright notice for your site, typically displayed in the footer. -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. +###### dataDir -### disableHugoGeneratorInject +(`string`) The directory from where Hugo reads data files. Default is `data`. {{% module-mounts-note %}} -**Default value:** false +###### defaultContentLanguage -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. +(`string`) Content without language indicator will default to this language. Default is `en`. -### disableKinds +###### defaultContentLanguageInSubdir -**Default value:** [] +(`bool`) Render the default content language in subdir, e.g. `content/en/`. The site root `/` will then redirect to `/en/`. Default is `false`. -Enable disabling of all pages of the specified *Kinds*. Allowed values in this list: `"page"`, `"home"`, `"section"`, `"taxonomy"`, `"term"`, `"RSS"`, `"sitemap"`, `"robotsTXT"`, `"404"`. +###### disableAliases -### disableLiveReload +(`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`. -**Default value:** false +###### disableHugoGeneratorInject -Disable automatic live reloading of browser window. +(`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`. -### disablePathToLower +###### disableKinds -**Default value:** false +(`string slice`) Disable rendering of the specified page [kinds], any of `404`, `home`, `page`, `robotstxt`, `rss`, `section`, `sitemap`, `taxonomy`, or `term`. -Do not convert the url/path to lowercase. +[kinds]: /getting-started/glossary/#page-kind -### enableEmoji +###### disableLiveReload -**Default value:** false +(`bool`) Disable automatic live reloading of browser window. Default is `false`. -Enable Emoji emoticons support for page content; see the [emoji shortcode quick reference guide](/quick-reference/emojis/). +###### disablePathToLower -### enableGitInfo +(`bool`) Do not convert the url/path to lowercase. Default is `false`. -**Default value:** false +###### enableEmoji -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. +(`bool`) Enable Emoji emoticons support for page content; see the [emoji shortcode quick reference guide](/quick-reference/emojis/). Default is `false`. -### enableInlineShortcodes +###### enableGitInfo -**Default value:** false +(`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`. -Enable inline shortcode support. See [Inline Shortcodes](/templates/shortcode-templates/#inline-shortcodes). +###### enableMissingTranslationPlaceholders -### enableMissingTranslationPlaceholders +(`bool`) Show a placeholder instead of the default value or an empty string if a translation is missing. Default is `false`. -**Default value:** false +###### enableRobotsTXT -Show a placeholder instead of the default value or an empty string if a translation is missing. +(`bool`) Enable generation of `robots.txt` file. Default is `false`. -### enableRobotsTXT - -**Default value:** false - -Enable generation of `robots.txt` file. - -### frontmatter +###### frontmatter See [Front matter Configuration](#configure-front-matter). -### hasCJKLanguage +###### hasCJKLanguage -**Default value:** false +(`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`. -If true, auto-detect Chinese/Japanese/Korean Languages in the content. This will make `.Summary` and `.WordCount` behave correctly for CJK languages. - -### imaging +###### imaging See [image processing configuration](/content-management/image-processing/#imaging-configuration). -### languageCode - -**Default value:** "" +###### languageCode -A language tag as defined by [RFC 5646](https://datatracker.ietf.org/doc/html/rfc5646). This value is used to populate: +(`string`) A language tag as defined by [RFC 5646](https://datatracker.ietf.org/doc/html/rfc5646). This value is used to populate: - The `<language>` element in the internal [RSS template](https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml) - The `lang` attribute of the `<html>` element in the internal [alias template](https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/alias.html) -### languages +###### languages See [Configure Languages](/content-management/multilingual/#configure-languages). -### disableLanguages +###### disableLanguages See [Disable a Language](/content-management/multilingual/#disable-a-language) -### markup +###### markup See [Configure Markup](/getting-started/configuration-markup). -### mediaTypes +###### mediaTypes See [Configure Media Types](/templates/output-formats/#media-types). -### menus +###### menus See [Menus](/content-management/menus/#define-in-site-configuration). -### minify +###### minify -See [Configure Minify](#configure-minify) +See [Configure Minify](#configure-minify). -### module +###### module Module configuration see [module configuration](/hugo-modules/configuration/). -### newContentEditor - -**Default value:** "" +###### newContentEditor -The editor to use when creating new content. +(`string`) The editor to use when creating new content. -### noChmod +###### noChmod -**Default value:** false +(`bool`) Don't sync permission mode of files. Default is `false`. -Don't sync permission mode of files. +###### noTimes -### noTimes +(`bool`) Don't sync modification time of files. Default is `false`. -**Default value:** false - -Don't sync modification time of files. - -### outputFormats +###### outputFormats See [Configure Output Formats](#configure-additional-output-formats). -### paginate - -**Default value:** 10 +###### paginate -Default number of elements per page in [pagination](/templates/pagination/). +(`int`) Default number of elements per page in [pagination](/templates/pagination/). Default is `10`. -### paginatePath +###### paginatePath -**Default value:** "page" +(`string`) The path element used during pagination (`https://example.org/page/2`). Default is `page`. -The path element used during pagination (`https://example.org/page/2`). - -### permalinks +###### permalinks See [Content Management](/content-management/urls/#permalinks). -### pluralizeListTitles - -**Default value:** true - -Pluralize titles in lists. +###### pluralizeListTitles -### publishDir +(`bool`) Pluralize titles in lists. Default is `true`. -**Default value:** "public" +###### publishDir -The directory to where Hugo will write the final static site (the HTML files etc.). +(`string`) The directory to where Hugo will write the final static site (the HTML files etc.). Default is `public`. -### related +###### related See [Related Content](/content-management/related/#configure-related-content). -### relativeURLs +###### relativeURLs -**Default value:** false +(`bool`) Enable this to make all relative URLs relative to content root. Note that this does not affect absolute URLs. Default is `false`. See [details](/content-management/urls/#relative-urls). -Enable this to make all relative URLs relative to content root. Note that this does not affect absolute URLs. See [details](/content-management/urls/#relative-urls). +###### refLinksErrorLevel -### 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`. -**Default value:** "ERROR" +###### refLinksNotFoundURL -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`). +(`string`) URL to be used as a placeholder when a page reference cannot be found in `ref` or `relref`. Is used as-is. -### refLinksNotFoundURL +###### removePathAccents -URL to be used as a placeholder when a page reference cannot be found in `ref` or `relref`. Is used as-is. - -### removePathAccents - -**Default value:** false - -Removes [non-spacing marks](https://www.compart.com/en/unicode/category/Mn) from [composite characters](https://en.wikipedia.org/wiki/Precomposed_character) in content paths. +(`bool`) Removes [non-spacing marks](https://www.compart.com/en/unicode/category/Mn) from [composite characters](https://en.wikipedia.org/wiki/Precomposed_character) in content paths. Default is `false`. ```text content/post/hügó.md → https://example.org/post/hugo/ ``` -### sectionPagesMenu +###### sectionPagesMenu See [Menus](/content-management/menus/#define-automatically). -### security +###### security -See [Security Policy](/about/security-model/#security-policy) +See [Security Policy](/about/security-model/#security-policy). -### sitemap +###### sitemap Default [sitemap configuration](/templates/sitemap-template/#configuration). -### summaryLength +###### summaryLength -**Default value:** 70 +(`int`) The length of text in words to show in a [`.Summary`](/content-management/summaries/#automatic-summary-splitting). Default is `70`. -The length of text in words to show in a [`.Summary`](/content-management/summaries/#automatic-summary-splitting). - -### taxonomies +###### taxonomies See [Configure Taxonomies](/content-management/taxonomies#configure-taxonomies). -### theme - -: See [module configuration](/hugo-modules/configuration/#module-configuration-imports) for how to import a theme. - -### themesDir +###### theme -**Default value:** "themes" +See [module configuration](/hugo-modules/configuration/#module-configuration-imports) for how to import a theme. -The directory where Hugo reads the themes from. +###### themesDir -### timeout +(`string`) The directory where Hugo reads the themes from. Default is `themes`. -**Default value:** "30s" +###### timeout -Timeout for generating page contents, specified as a [duration](https://pkg.go.dev/time#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). +(`string`) Timeout for generating page contents, specified as a [duration](https://pkg.go.dev/time#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 +###### timeZone -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](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). +(`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](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). -### title +###### title -Site title. +(`string`) Site title. -### titleCaseStyle +###### titleCaseStyle -**Default value:** "ap" +(`string`) Default is `ap`. See [Configure Title Case](#configure-title-case). -See [Configure Title Case](#configure-title-case) +###### uglyURLs -### uglyURLs +(`bool`) When enabled, creates URL of the form `/filename.html` instead of `/filename/`. Default is `false`. -**Default value:** false +###### watch -When enabled, creates URL of the form `/filename.html` instead of `/filename/`. - -### watch - -**Default value:** false - -Watch filesystem for changes and recreate as needed. +(`bool`) Watch filesystem for changes and recreate as needed. Default is `false`. {{% note %}} If you are developing your site on a \*nix machine, here is a handy shortcut for finding a configuration option from the command line: @@ -567,7 +539,7 @@ The `build.cachebusters` configuration option was added to support development u target = "$1" {{< /code-toggle >}} -Some key points in the above are `writeStats = true`, which 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](https://github.com/bep/hugo-starter-tailwind-basic) for a running example. +When `buildStats` {{< new-in 0.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](https://github.com/bep/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/...`. @@ -664,35 +636,6 @@ none HUGO_NUMWORKERMULTIPLIER : Can be set to increase or reduce the number of workers used in parallel processing in Hugo. If not set, the number of logical CPUs will be used. -## Configuration lookup order - -Similar to the template [lookup order], Hugo has a default set of rules for searching for a configuration file in the root of your website's source directory as a default behavior: - -1. `./hugo.toml` -2. `./hugo.yaml` -3. `./hugo.json` - -In your configuration file, you can direct Hugo as to how you want your website rendered, control your website's menus, and arbitrarily define site-wide parameters specific to your project. - -## Example configuration - -The following is a typical example of a configuration file. The values nested under `params:` will populate the [`.Site.Params`] variable for use in [templates]: - -{{< code-toggle file=hugo >}} -baseURL: "https://yoursite.example.com/" -title: "My Hugo Site" -permalinks: - posts: /:year/:month/:title/ -params: - Subtitle: "Hugo is Absurdly Fast!" - AuthorName: "Jon Doe" - GitHubUser: "spf13" - ListOfFoo: - - "foo1" - - "foo2" - SidebarRecentLimit: 5 -{{< /code-toggle >}} - ## Configure with environment variables In addition to the 3 configuration options already mentioned, configuration key-values can be defined through operating system environment variables. @@ -789,6 +732,10 @@ Hugo v0.20 introduced the ability to render your content to multiple output form ## Configure minify +See the [tdewolff/minify] project page for details. + +[tdewolff/minify]: https://github.com/tdewolff/minify + Default configuration: {{< code-toggle config=minify />}} @@ -818,22 +765,6 @@ maxAge dir : (`string`) The absolute path to where the files for this cache will be stored. Allowed starting placeholders are `:cacheDir` and `:resourceDir` (see above). -## Configuration format specs - -- [TOML Spec][toml] -- [YAML Spec][yaml] -- [JSON Spec][json] - -[`.Site.Params`]: /variables/site/ -[directory structure]: /getting-started/directory-structure -[json]: https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf -[lookup order]: /templates/lookup-order/ -[Output Formats]: /templates/output-formats/ -[templates]: /templates/ -[toml]: https://toml.io/en/latest -[yaml]: https://yaml.org/spec/ -[static-files]: /content-management/static-files/ - ## Configure cacheDir This is the directory where Hugo by default will store its file caches. See [Configure File Caches](#configure-file-caches). @@ -849,3 +780,9 @@ If this is not set, Hugo will use, in order of preference: If you want to know the current value of `cacheDir`, you can run `hugo config`, e.g: `hugo config | grep cachedir`. [`time`]: /functions/time/astime +[`.Site.Params`]: /variables/site/ +[directory structure]: /getting-started/directory-structure +[lookup order]: /templates/lookup-order/ +[Output Formats]: /templates/output-formats/ +[templates]: /templates/ +[static-files]: /content-management/static-files/ |