HUGO
Menu
GitHub 87548 stars Mastodon

PublishDate

返回给定页面的发布日期。

Syntax

PAGE.PublishDate

Returns

time.Time

默认情况下,Hugo 在构建站点时会排除发布日期为未来的页面。要包含未来页面,请使用 --buildFuture 命令行标志。

在 front matter 中设置发布日期:

---
publishDate: 2023-10-19T00:40:04-07:00
title: Article 1
---
+++
publishDate = 2023-10-19T00:40:04-07:00
title = 'Article 1'
+++
{
   "publishDate": "2023-10-19T00:40:04-07:00",
   "title": "Article 1"
}

发布日期是 time.Time 值。使用 time.Format 函数格式化和本地化值,或将其与任何 时间方法 一起使用。

{{ .PublishDate | time.Format ":date_medium" }} → Oct 19, 2023

在上面的示例中,我们在 front matter 中显式设置了发布日期。使用 Hugo 的默认配置,PublishDate 方法返回 front matter 值。此行为是可配置的,允许您在 front matter 中未定义发布日期时设置回退值。详见 详情


Last updated: January 1, 0001
Improve this page