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