80dd7b067 theme: Fix border class in render-codeblock template 0d3fde6c9 content: Fix typo 23a4adb29 content: More site => project changes 9243e9f6b content: Rename site configuration to project configuration (phase 2) 330aa2249 content: Miscellaneous edits 25ce893be content: Clarify sort order with PAGE.Rotate b398506dc content: Various dimension improvements c54573d13 content: Use singular form in method section descriptions d9a95fe54 content: Improve description of PAGE.Rotate 154f30600 content: Fix link c71bd2776 content: Address Markdown linting error 72c88e68e content: Improve pages related to content dimensions b85afa645 content: Fix formatting 7aaca8947 content: More site-to-project changes 8e1579030 content: Update quick start guide f7ba1fde2 content: Make new-in into a note 8b9d51584 theme: Address TailwindCSS warnings 3a4c2a25c theme: Address Hugo v0.156.0 deprecations 4f1a2bd7b content: Improve glossary entries 21bcd23a6 content: Update glossary entry c72ef1116 content: Update quick start guide c0737ffab content: Add typography plugin to TailwindCSS example 80bcb868e content: Remove Site.AllPages from examples 2b9ba5831 content: Replace Page.Sites and Site.Sites with hugo.Sites 2cdcc2556 content: Remove outdated badges 5a4beb530 content: Replace Site.Data with hugo.Data de4651b5d content: Update glossary entry 2302825a7 content: Add hugo.Data and note other deprecations bac5da4b5 content: Add hugo.Sites and update the other Sites methods 0f7d99153 content: Add Site.IsDefault f888f33bb content: Update glossary entries 65311c2de content: Include the "build" subcommand where appropriate 4991320d2 content: Standard shell language code in info strings b16d9f162 theme: Style todo lists f121450c6 content: Update version references 5a81dd8c2 content: Update CLI documentation f3ae0ce86 content: Rename site configuration to project configuration (phase 1) 9c8327119 content: Miscellaneous edits fbff91e22 Update HUGO_VERSION to 0.156.0 2ec625ae8 content: Restore snap installation instructions fc8c246b8 content: Clarify module initialization git-subtree-dir: docs git-subtree-split: 80dd7b067c31c28b13c51f3ac4636890509a4bb7
3.5 KiB
title, linkTitle, description, categories, keywords
| title | linkTitle | description | categories | keywords |
|---|---|---|---|---|
| Configure front matter | Front matter | Configure front matter. |
Dates
There are four methods on a Page object that return a date.
| Method | Description |
|---|---|
Date |
Returns the date of the given page. |
ExpiryDate |
Returns the expiry date of the given page. |
Lastmod |
Returns the last modification date of the given page. |
PublishDate |
Returns the publish date of the given page. |
Hugo determines the values to return based on this configuration:
{{< code-toggle config=frontmatter />}}
The ExpiryDate method, for example, returns the expirydate value if it exists, otherwise it returns unpublishdate.
You can also use custom date parameters:
{{< code-toggle file=hugo >}} [frontmatter] date = ["myDate", "date"] {{< /code-toggle >}}
In the example above, the Date method returns the myDate value if it exists, otherwise it returns date.
To fall back to the default sequence of dates, use the :default token:
{{< code-toggle file=hugo >}} [frontmatter] date = ["myDate", ":default"] {{< /code-toggle >}}
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.
Aliases
Some of the front matter fields have aliases.
| Front matter field | Aliases |
|---|---|
expiryDate |
unpublishdate |
lastmod |
modified |
publishDate |
pubdate, published |
The default front matter configuration includes these aliases.
Tokens
Hugo provides the following tokens to help you configure your front matter:
:default- The default ordered sequence of date fields.
:fileModTime- The file's last modification timestamp.
:filename- Extracts the date from the file name, provided the file name begins with a date in one of the following formats:
YYYY-MM-DDYYYY-MM-DD-HH-MM-SS{{< new-in 0.148.0 />}}
Within the
YYYY-MM-DD-HH-MM-SSformat, the date and time values may be separated by any character including a space (e.g.,2025-02-01T14-30-00).Hugo resolves the extracted date to the
timeZonedefined in your project configuration, falling back to the system time zone. After extracting the date, Hugo uses the remaining part of the file name to generate the page'sslug, but only if you haven't already specified a slug in the page's front matter.For example, if you name your file
2025-02-01-article.md, Hugo will set the date to2025-02-01and the slug toarticle. :git- The Git author date for the file's last revision. To enable access to the Git author date, set
enableGitInfototrue, or use the--enableGitInfoflag when building your project.
Example
Consider this project configuration:
{{< code-toggle file=hugo >}} [frontmatter] date = [':filename', ':default'] publishDate = [':filename', ':default'] lastmod = ['lastmod', ':fileModTime'] {{< /code-toggle >}}
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.
To determine lastmod, Hugo looks for a lastmod field in front matter, falling back to the file's last modification timestamp.