HUGO
Menu
GitHub 87548 stars Mastodon

Lastmod

返回给定页面的最后修改日期。

Syntax

PAGE.Lastmod

Returns

time.Time

在 front matter 中设置最后修改日期:

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

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

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

在上面的示例中,我们在 front matter 中显式设置了最后修改日期。使用 Hugo 的默认配置,Lastmod 方法返回 front matter 值。此行为是可配置的,允许您:

  • 将最后修改日期设置为该文件最后一次 Git 提交的作者日期。详见 GitInfo
  • 如果 front matter 中未定义最后修改日期,则设置回退值。

了解有关 日期配置 的更多信息。


Last updated: January 1, 0001
Improve this page