| 1 |
--- |
| 2 |
title: Configure front matter |
| 3 |
linkTitle: Front matter |
| 4 |
description: Configure front matter. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
## Dates |
| 10 |
|
| 11 |
There are four methods on a `Page` object that return a date. |
| 12 |
|
| 13 |
Method|Description |
| 14 |
:--|:-- |
| 15 |
[`Date`][]|Returns the date of the given page. |
| 16 |
[`ExpiryDate`][]|Returns the expiry date of the given page. |
| 17 |
[`Lastmod`][]|Returns the last modification date of the given page. |
| 18 |
[`PublishDate`][]|Returns the publish date of the given page. |
| 19 |
|
| 20 |
Hugo determines the values to return based on this configuration: |
| 21 |
|
| 22 |
{{< code-toggle config=frontmatter />}} |
| 23 |
|
| 24 |
The `ExpiryDate` method, for example, returns the `expirydate` value if it exists, otherwise it returns `unpublishdate`. |
| 25 |
|
| 26 |
You can also use custom date parameters: |
| 27 |
|
| 28 |
{{< code-toggle file=hugo >}} |
| 29 |
[frontmatter] |
| 30 |
date = ["myDate", "date"] |
| 31 |
{{< /code-toggle >}} |
| 32 |
|
| 33 |
In the example above, the `Date` method returns the `myDate` value if it exists, otherwise it returns `date`. |
| 34 |
|
| 35 |
To fall back to the default sequence of dates, use the `:default` token: |
| 36 |
|
| 37 |
{{< code-toggle file=hugo >}} |
| 38 |
[frontmatter] |
| 39 |
date = ["myDate", ":default"] |
| 40 |
{{< /code-toggle >}} |
| 41 |
|
| 42 |
In the example above, the `Date` method returns the `myDate` value if it exists, otherwise it returns the first valid date from `date`, `publishdate`, `pubdate`, `published`, `lastmod`, and `modified`. |
| 43 |
|
| 44 |
## Aliases |
| 45 |
|
| 46 |
Some of the front matter fields have aliases. |
| 47 |
|
| 48 |
Front matter field|Aliases |
| 49 |
:--|:-- |
| 50 |
`expiryDate`|`unpublishdate` |
| 51 |
`lastmod`|`modified` |
| 52 |
`publishDate`|`pubdate`, `published` |
| 53 |
|
| 54 |
The default front matter configuration includes these aliases. |
| 55 |
|
| 56 |
## Tokens |
| 57 |
|
| 58 |
Hugo provides the following [tokens](g) to help you configure your front matter: |
| 59 |
|
| 60 |
`:default` |
| 61 |
: The default ordered sequence of date fields. |
| 62 |
|
| 63 |
`:fileModTime` |
| 64 |
: The file's last modification timestamp. |
| 65 |
|
| 66 |
`:filename` |
| 67 |
: Extracts the date from the file name, provided the file name begins with a date in one of the following formats: |
| 68 |
|
| 69 |
- `YYYY-MM-DD` |
| 70 |
- `YYYY-MM-DD-HH-MM-SS` {{< new-in 0.148.0 />}} |
| 71 |
|
| 72 |
Within the `YYYY-MM-DD-HH-MM-SS` format, the date and time values may be separated by any character including a space (e.g., `2025-02-01T14-30-00`). |
| 73 |
|
| 74 |
Hugo resolves the extracted date to the [`timeZone`][] defined in your project configuration, falling back to the system time zone. Hugo also derives the page [`slug`][] from the remaining file name, unless the page already defines a `slug` in its front matter. |
| 75 |
|
| 76 |
Slug inference only occurs when `:filename` is the winning date source. If an earlier entry in the list provides a valid date, Hugo skips `:filename` entirely. For example, with `date = ["date", ":filename"]`, a page that defines `date` in its front matter will use that value, and the slug will not be inferred from the file name. |
| 77 |
|
| 78 |
For example, if you name your file `2025-02-01-article.md`, Hugo will set the date to `2025-02-01` and the slug to `article`. |
| 79 |
|
| 80 |
`:git` |
| 81 |
: The Git author date for the file's last revision. To enable access to the Git author date, set [`enableGitInfo`][] to `true`. |
| 82 |
|
| 83 |
## Example |
| 84 |
|
| 85 |
Consider this project configuration: |
| 86 |
|
| 87 |
{{< code-toggle file=hugo >}} |
| 88 |
[frontmatter] |
| 89 |
date = [':filename', ':default'] |
| 90 |
publishDate = [':filename', ':default'] |
| 91 |
lastmod = ['lastmod', ':fileModTime'] |
| 92 |
{{< /code-toggle >}} |
| 93 |
|
| 94 |
To determine `date` and `publishDate`, Hugo tries to extract the value from the file name, falling back to the default ordered sequence of date fields. |
| 95 |
|
| 96 |
To determine `lastmod`, Hugo looks for a `lastmod` field in front matter, falling back to the file's last modification timestamp. |
| 97 |
|
| 98 |
[`Date`]: /methods/page/date/ |
| 99 |
[`ExpiryDate`]: /methods/page/expirydate/ |
| 100 |
[`Lastmod`]: /methods/page/lastmod/ |
| 101 |
[`PublishDate`]: /methods/page/publishdate/ |
| 102 |
[`enableGitInfo`]: /configuration/all/#enablegitinfo |
| 103 |
[`slug`]: /content-management/front-matter/#slug |
| 104 |
[`timeZone`]: /configuration/all/#timezone |