Hugo学习笔记七,自动更新文件中的修改时间

hugo中文件头有lastmod,可以在更改时,写入更改时间。可是我不想每次都改,想要自动更如何用呢?

基实hugo己经有这个功能了,只要在config.toml中设置就行了

1
2
3
4
5
6
[frontmatter]
# 意为,变量 .Date 将会被赋值为 数组中最先找到的的日期值
# date = ["lastmod", "date", "publishDate" ]
lastmod = [':fileModTime', 'lastmod', ':git', ':default']
# lastmod = ["lastmod", "date", ":git", "publishDate"]

  1. :git 从文件的 git 提交记录获取
  2. lastmod 从文件中的 lastmod 字段获取
  3. :fileModTime’ 从文件修改时间获取, 只要把这个放在字段第一个就行
  4. publishDate 文章发布时间

hugo如果想让文章排序从更新时间排如何设呢?

1
2
3
4
5
6
[frontmatter]
# 意为,变量 .Date 将会被赋值为 数组中最先找到的的日期值
date = ["lastmod", "date", "publishDate" ]
# lastmod = [':fileModTime', 'lastmod', ':git', ':default']
# lastmod = ["lastmod", "date", ":git", "publishDate"]

只要把date的字段第一个设为“lastmod”就行 date = [“lastmod”,…]